c # delete drawstring in picturebox


I have a pictureBox where the user at each click of the mouse inserts a text on top of an image in a pictureBox. It inserts several texts in several points of the image, the inserted text gets picked up from checkboxes.

Using this code

 private void pictureBox2_MouseClick(object sender, MouseEventArgs e)
        var g = Graphics.FromImage(pictureBox2.Image);
        var mouseEventArgs = e as MouseEventArgs;
        if (mouseEventArgs != null) textBox1.Text = "X= " + mouseEventArgs.X + " Y= " + mouseEventArgs.Y;

        g.DrawString(texto, new Font("Verdana", 30F, FontStyle.Regular), Brushes.Red, new PointF(e.X * pictureBox2.Image.Width / pictureBox2.Width -30,
e.Y * pictureBox2.Image.Height / pictureBox2.Height -90));

What I can not do is to delete the texts. I wish he could delete anyone he inserted in any order. I thought of a kind of CTRL + Z but this would delete one by one, if it already inserted 5, and want to delete only the first one, ctrl + z would no longer work.

I thought of a kind of rubber, that he was wiping his mouse over the text he inserted and erasing, without erasing the background image. Or by the very checkbox that he clicked to choose which text to write, if he clicks the checkbox again the drawstring that matches that text of the checkbox delete.

Is it possible to delete these drawstring? The easiest way, I'm a beginner.

asked by anonymous 02.08.2017 / 18:45

1 answer


To make an eraser, I used the following command:

    private void Borracha(MouseEventArgs e)
        int t = int.Parse(tam.ToString());
        var g = Graphics.FromImage(pic1.Image);
        g.FillEllipse(new SolidBrush(Color.Magenta), e.X - (t / 2), e.Y - (t / 2), t, t);
        Bitmap b = (Bitmap)pic1.Image;
        pic1.Image = b;
02.08.2017 / 19:02