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 a closed curve in VB .NET, filled with a hatch pattern and outlined with a custom dash pattern
Keywordshatched, closedcurve, closed curve, hatch, dash, dashed line, VB.NET
CategoriesGraphics, VB.NET
 
A "closed curve" in this context is a closed spline defined by an array of points. The spline doesn't connect the points exactly; it draws a smoother curve that roughly follows the points.

The example creates an array of Point objects to define the points. It uses a Graphics object's FillClosedSurve method to fill the curve. This example uses a HatchBrush to fill the curve with a hatch pattern.

The example then creates a Pen object. It creates an array of Single values to define a custom dash pattern. The values indicate the number of pixels drawn, skipped, drawn, skipped, etc. The program sets the Pen's DashPattern property to this array of values and then sets its DashStyle to Custom. Finally the program calls the Graphics object's DrawClosedCurve method to outline the curve.

 
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles _
    MyBase.Paint
    Dim pts() As Point = { _
        New Point(20, 5), _
        New Point(100, 30), _
        New Point(80, 100), _
        New Point(120, 120), _
        New Point(60, 140), _
        New Point(5, 60) _
    }

    ' Fill a closed curve a hatched brush.
    e.Graphics.FillClosedCurve( _
        New HatchBrush( _
            HatchStyle.LargeConfetti, _
            Color.Blue, _
            Color.LightBlue), _
        pts)

    ' Make a pen.
    Dim a_pen As New Pen(Color.DarkSlateBlue, 3)
    Dim dash_pattern As Single() = {10, 2, 5, 2}
    a_pen.DashPattern = dash_pattern
    a_pen.DashStyle = DashStyle.Custom

    ' Outline the closed curve.
    e.Graphics.DrawClosedCurve(a_pen, pts)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated