Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleMake a text-shaped PictureBox
Keywordstext-shaped picture box, SetWindowRgn, region, shape, PictureBox
CategoriesControls, Graphics, API
 
Use the BeginPath, EndPath, SelectClipPath, PathToRegion, and SetWindowRgn API functions.
 
Private Sub Form_Load()
Const TXT = "Hello!"

Dim i As Long
Dim hRgn As Long

    Picture1.AutoRedraw = True

    ' Select a big font.
    Picture1.Font.Name = "Times New Roman"
    Picture1.Font.Bold = True
    Picture1.Font.Size = 50

    ' Make the PictureBox big enough.
    Picture1.Width = Picture1.TextWidth(TXT)
    Picture1.Height = Picture1.TextHeight(TXT)

    ' Make the clipping path.
    BeginPath Picture1.hdc
    Picture1.CurrentX = 0
    Picture1.CurrentY = 0
    Picture1.Print TXT
    EndPath Picture1.hdc

    ' Convert the path into a region.
    hRgn = PathToRegion(Picture1.hdc)

    ' Constrain the PictureBox to the region.
    SetWindowRgn Picture1.hWnd, hRgn, False

    ' Draw some lines on the form.
    AutoRedraw = True
    For i = 0 To ScaleHeight Step 60
        Line (0, i)-Step(ScaleWidth, 0), RGB(0, 128, 255)
    Next i

    ' Start the timer.
    Timer1.Enabled = True
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated