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 on top of a gradient Brush in VB .NET
DescriptionThis example shows how to draw lines on top of a gradient Brush in VB .NET. The result is that the lines appear to show parts of the underlying pattern created by the Brush.
KeywordsBrush, Pen, PathGradientBrush
CategoriesVB.NET, Graphics
 
The program first makes a PathGradientBrush that covers the form's client area. It sets the Brush's InterpolationColors property to make the brush blend radially from red to green to blue.

Next the program uses the Brush to create a Pen. It then draws with the Pen.

 
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles _
    MyBase.Paint
    ' Make a brush that covers the form.
    Dim graphics_path As New GraphicsPath
    graphics_path.AddRectangle(Me.ClientRectangle)
    Dim the_brush As New PathGradientBrush(graphics_path)

    ' Make a color blend from red to green to blue.
    Dim color_blend As New ColorBlend
    color_blend.Colors = New Color() {Color.Red, _
        Color.Green, Color.Blue}
    color_blend.Positions = New Single() {0.0, 0.5, 1.0}
    the_brush.InterpolationColors = color_blend

    ' Make a pen from the brush.
    Dim the_pen As New Pen(the_brush, 20)
    the_pen.StartCap = LineCap.Round
    the_pen.EndCap = LineCap.Round

    ' Draw some stuff.
    e.Graphics.DrawEllipse(the_pen, 20, 20, _
        Me.ClientSize.Width - 2 * 20, Me.ClientSize.Height _
        - 2 * 20)
    e.Graphics.DrawLine(the_pen, 20, 20, _
        Me.ClientSize.Width - 20, Me.ClientSize.Height - 20)
    e.Graphics.DrawLine(the_pen, Me.ClientSize.Width - 20, _
        20, 20, Me.ClientSize.Height - 20)

    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