|
|
Title | Draw a five-pointed star in Visual Basic .NET |
Description | This example shows how to draw a five-pointed star in Visual Basic .NET. |
Keywords | star, five-pointed star, draw, VB.NET |
Categories | VB.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
|
|
|
|
|
|