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
 
 
 
 
 
 
TitleDraw lines that lie along a color gradient in VB .NET
DescriptionThis example shows how to draw lines that lie along a color gradient in VB .NET. Each line draws with its own LinearGradientBrush defined to lie along itself.
KeywordsBrush, Pen, LinearGradientBrush, color, blend, drawing, DrawGradientLine
CategoriesVB.NET, Graphics
 
Subroutine DrawGradientLine creates a LinearGradientBrush that lies between the line's start and end points. It then uses the Brush to make a Pen and draws with the Pen.
 
' Draw a line from (x1, y1) to (x2, y2) fading from
' color1 to color2.
Private Sub DrawGradientLine(ByVal gr As Graphics, ByVal _
    point1 As Point, ByVal point2 As Point, ByVal color1 As _
    Color, ByVal color2 As Color, ByVal line_width As _
    Single)
    ' Make the brush.
    Dim the_brush As New LinearGradientBrush( _
        point1, point2, color1, color2)
    the_brush.WrapMode = WrapMode.TileFlipX

    ' Use the brush to make the pen.
    Dim the_pen As New Pen(the_brush, line_width)
    the_pen.StartCap = LineCap.Round
    the_pen.EndCap = LineCap.Round

    ' Draw the line.
    gr.DrawLine(the_pen, point1, point2)

    ' Clean up.
    the_pen.Dispose()
    the_brush.Dispose()
End Sub
 
My next book includes a lot more information on Pens, Brushes, and other drawing objects in VS 2005. Check the VB Helper Web site or sign up for my newsletter to learn more about this book when it is available.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated