Each click on the picturebox draws a circle, and I want to make it so that when I have drawn 3 circles, the next click deletes them all and draws a new one. But I haven't been able to find a way to do it.
Code in picturebox1_click:
Code in picturebox1_paint:
Circle Class:
Code in picturebox1_click:
Code:
If e.Button = MouseButtons.Left Then 'draw circles and stop them from being erased on .Invalidate
If e.Button = MouseButtons.Left Then
Dim newcircle As New circle(PictureBox1.PointToClient(Cursor.Position), 5, Color.Black)
Circles.Add(newcircle)
PictureBox1.Invalidate()
End If
End If
Code:
For Each c As circle In Circles
c.Draw(e.Graphics)
Next
Code:
Public Class circle
Public Position As Point
Public Radius As Integer
Public PenColor As Color
Private Rect As Rectangle
Public Sub New(ByVal P As Point, ByVal R As Integer, ByVal C As Color)
Position = P
Radius = R
PenColor = C
Rect = New Rectangle(P.X - (R), P.Y - (R), R * 2, R * 2)
End Sub
Public Sub Draw(ByVal G As Graphics)
Dim P As Pen = New Pen(PenColor)
Dim yellowbrush As New SolidBrush(Color.Yellow)
G.DrawEllipse(P, Rect)
G.FillEllipse(yellowbrush, Rect)
End Sub
End Class