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
 
 
 
 
 
TitleDisplay the available dash styles in VB .NET
DescriptionThis example shows how to display the available dash styles in VB .NET. It iterates through the DashStyle values, displaying examples of each.
KeywordsDashStyle, dash style, VB.NET, pen
CategoriesVB.NET, Graphics
 
The program loops through each of the numeric DashStyle values, calling DrawDashSample.

Subroutine DrawDashSample draws the DashStyle's name and a rectangle drawn using that style.

 
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles _
    MyBase.Paint
    ' Currently the dash styles have values 0 to 5.
    Const MIN_PATTERN As Integer = 0
    Const MAX_PATTERN As Integer = 5
    Dim x As Integer = 10
    Dim y As Integer = 10

    For i As Integer = MIN_PATTERN To MAX_PATTERN
        DrawDashSample(e.Graphics, x, y, CType(i, _
            DashStyle))
    Next i
End Sub

Private Sub DrawDashSample(ByVal gr As Graphics, ByRef x As _
    Integer, ByRef y As Integer, ByVal dash_style As _
    DashStyle)
    Const TEXT_WID As Integer = 100
    Const RECT_WID As Integer = 50
    Const RECT_HGT As Integer = 40

    Dim the_pen As New Pen(Color.Black)
    the_pen.DashStyle = dash_style
    gr.DrawString( _
        dash_style.ToString & " (" & CInt(dash_style) & _
            ")", _
        Me.Font, Brushes.Black, x, y)
    gr.DrawRectangle(the_pen, x + TEXT_WID, y, RECT_WID, _
        RECT_HGT)
    the_pen.Dispose()

    y += RECT_HGT + 10
    If y + RECT_HGT > Me.ClientSize.Height Then
        x += TEXT_WID + RECT_WID + 30
        y = 10
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated