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 five-pointed star in Visual Basic .NET
DescriptionThis example shows how to draw a five-pointed star in Visual Basic .NET.
Keywordsstar, five-pointed star, draw, VB.NET
CategoriesVB.NET, Graphics
 
The program allocates an array to hold the star's points. It then loops through the array creating points offset from the form's center. The points lie on an ellipse that would touch the form's four edges. The angle from the center to the first point is -Pi/2 radians (up). Each point after that is at the angle 2 * Pi * 2/5 radians larger than the previous angle.
 
' Draw a star.
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles _
    MyBase.Paint
    ' Make the points for a star.
    Dim pts(4) As Point
    Dim cx As Integer = Me.ClientSize.Width \ 2
    Dim cy As Integer = Me.ClientSize.Height \ 2
    Dim theta As Double = -Math.PI / 2
    Dim dtheta As Double = Math.PI * 0.8
    For i As Integer = 0 To 4
        pts(i).X = CInt(cx + cx * Cos(theta))
        pts(i).Y = CInt(cy + cy * Sin(theta))
        theta += dtheta
    Next i

    ' Draw.
    e.Graphics.DrawPolygon(Pens.Red, pts)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated