Haegendoorn
New member
- Joined
- Apr 7, 2008
- Messages
- 4
- Programming Experience
- Beginner
Hi,
I have to develop an application that creates a polygon. The points of the polygon should be defined by several random mouse clicks inside the picturebox.
My problem is that i can t dynamically add points to an array of points because i get the error: 'Object reference not set to an instance of an object.'
This is my code
I have to develop an application that creates a polygon. The points of the polygon should be defined by several random mouse clicks inside the picturebox.
My problem is that i can t dynamically add points to an array of points because i get the error: 'Object reference not set to an instance of an object.'
This is my code
VB.NET:
Dim MyPoints() As Point
Dim Clicks As Integer = 0
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
' add point to polygon
MyPoints(Clicks) = New Point(Windows.Forms.Cursor.Position.X - Me.Location.X, _
Windows.Forms.Cursor.Position.Y - Me.Location.Y - 27)
Clicks += 1
If Clicks > 2 Then
DrawPolygon()
End If
End Sub
Sub DrawPolygon()
Dim BM As New Bitmap(250, 250)
Dim G As Graphics = Graphics.FromImage(BM)
G.DrawPolygon(Pens.Black, MyPoints)
PictureBox1.Image = BM
End Sub