Home
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
 
 
 
 
TitleDraw text filled with a color gradient in VB .NET
Keywordsfilled text, outline text, text, region, SetClip, FillPath, color, gradient
CategoriesGraphics
 
In the form's Paint event handler, create a GraphicsPath object. Use its AddString method to add the string to it.

Call the Graphics object's FillPath method to fill the text path with blue. Then call the Graphics object's SetClip method to make the object use the path as its clipping path.

Now draw lines that fill the form, gradually changing their colors to form the gradient.

 
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles _
    MyBase.Paint
    Dim text_path As GraphicsPath

    ' Create the text path.
    text_path = New System.Drawing.Drawing2D.GraphicsPath( _
        Drawing.Drawing2D.FillMode.Alternate)
    text_path.AddString("Flowers", _
        New FontFamily("Times New Roman"), _
        FontStyle.Bold, 200, _
        New Point(10, 10), _
        StringFormat.GenericDefault)

    ' Fill the path with blue.
    e.Graphics.FillPath(New SolidBrush(Color.Blue), _
        text_path)

    ' Use the path as the Graphics
    ' object's clipping region.
    e.Graphics.SetClip(text_path)

    ' Draw lines on the form.
    Dim dg As Single
    Dim g As Single
    Dim y As Integer
    dg = -255 / (Me.Height + 1)
    g = 255
    For y = 0 To Me.Height
        e.Graphics.DrawLine( _
            New Pen(Color.FromArgb(255, 0, g, 0), 2), _
            0, y, 1000, y)
        g += dg
    Next y
End Sub
 
Click here to compare this code to the version used for VB 6.
 
 
Copyright © 1997-2001 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated