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
 
 
 
 
 
TitleClip lines to the boundary of a text string
Keywordsclip, clipping, text, lines, path
CategoriesGraphics
 
Use the BeginPath, EndPath, and SelectClipPath API functions to set the form's clipping path. Then draw the lines.

This program first fills the text with horizontal lines. Then it draws the text again, filling it with 1,000 random lines.

 
Private Sub Form_Load()
Const TXT = "Hello!"

Dim i As Long
Dim clr As Single
Dim dclr As Single
Dim ymin As Single
Dim hgt As Single
Dim wid As Single

    AutoRedraw = True

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

    ' Make the form big enough.
    Width = TextWidth(TXT) + 240 + Width - ScaleWidth
    Height = 2 * TextHeight(TXT) + 2 * 240 + Height - _
        ScaleHeight
    wid = ScaleWidth

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

    ' Select the clipping path.
    SelectClipPath hdc, RGN_COPY

    ' Draw some colored lines through the text.
    dclr = 256 / (TextHeight(TXT) / 30)
    clr = 0
    For i = 120 To 120 + TextHeight(TXT) Step 30
        Line (0, i)-Step(wid, 0), RGB(0, 0, clr)
        clr = clr + dclr
    Next i

    ' Do it again.
    ' Make the clipping path.
    BeginPath hdc
    CurrentX = 120
    hgt = TextHeight(TXT)
    ymin = hgt + 2 * 120
    CurrentY = ymin
    Print TXT
    EndPath hdc

    ' Select the clipping path.
    SelectClipPath hdc, RGN_COPY

    ' Draw some colored lines through the text.
    For i = 1 To 1000
        Line (Rnd * ScaleWidth, ymin + Rnd * hgt)-(Rnd * _
            ScaleWidth, ymin + Rnd * hgt), QBColor(Int(16 * _
            Rnd))
    Next i
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated