Quantcast
Viewing all articles
Browse latest Browse all 42292

VS 2010 [RESOLVED] How to delete ellipses?

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:

        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 in picturebox1_paint:

Code:

        For Each c As circle In Circles
            c.Draw(e.Graphics)
        Next

Circle Class:

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


Viewing all articles
Browse latest Browse all 42292

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>