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 are filled with a hatch pattern in VB .NET
DescriptionThis example shows how to draw lines that are filled with a hatch pattern in VB .NET. The lines are defined by HatchBrush objects.
KeywordsBrush, Pen, HatchBrush, drawing, DrawHatchLine
CategoriesVB.NET, Graphics
 
Subroutine DrawHatchLine creates an appropriate HatchBrush and uses the Brush to define a Pen. It then draws with the Pen.
 
' Draw a line from (x1, y1) to (x2, y2) 
' using the desired texture.
Private Sub DrawHatchLine(ByVal gr As Graphics, ByVal _
    point1 As Point, ByVal point2 As Point, ByVal _
    hatch_style As HatchStyle, ByVal fore_color As Color, _
    ByVal back_color As Color, ByVal line_width As Single)
    ' Make the brush.
    Dim the_brush As New HatchBrush( _
        hatch_style, fore_color, back_color)

    ' 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