Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
After every click on the picturebox the program will place a circle with a one in it. The next click will put a 2 and so on. I added an undo button if the user accidentally clicked when they didn't want to. How can I delete the text that was written into the picturebox?

What I have tried:

This is the code I have used to write the circle with the number inside of it:
Public Class Form1
    Dim Counter As Integer
    Dim g As Graphics
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        g = PictureBox1.CreateGraphics
        Counter = 0
    End Sub

    Private Sub PictureBox1_MouseDown(sender As Object, e As EventArgs) Handles PictureBox1.MouseDown
        Dim X As Integer
        Dim Y As Integer
        Dim f As New Font("Arial", 10)
        X = Cursor.Position.X
        Y = Cursor.Position.Y
        Counter = Counter + 1
        TextBox1.Text = Counter
        If Counter = 1 Then
            g.DrawEllipse(Pens.Black, New Rectangle(X - 289, Y - 157, 20, 20))
            g.DrawString("1.", f, Brushes.Black, New Point(X - 285, Y - 155))
        End If
        If Counter = 2 Then
            g.DrawEllipse(Pens.Black, New Rectangle(X - 289, Y - 157, 20, 20))
            g.DrawString("2.", f, Brushes.Black, New Point(X - 285, Y - 155))
        End If
    End Sub
End Class
Posted
Updated 26-Aug-18 16:19pm

Basically, you can't. Once it's drawn it's permanent.

So, what you have to do is implement Undo functionality. In a rather simplistic implementation, that means keeping track of each operation (change) you make to the picture.

When you undo an operation, you start over, applying each operation you added to the list to the original image you started with, except for the last one. There's your "undone" step.
 
Share this answer
 
If the picturebox background is one color, you can set your circle color to be the same color using a color picker if necessary, and draw it again in the same place. Prest-o change-o it's gone. Set your color back and soldier on.

I've done this.
 
Share this answer
 
Quote:
How can I delete the text that was written into the picturebox?

Short answer: as told by previous solutions, you can't delete last change.
Because any change is cumulative, and can overlap things already in picture, it is impossible to know what was overwritten by change.
The only way is to memorize the original picture and every change done in a way that will allow you to rebuild the picture up to previous state.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900