Reputation: 49
I made several drawings using Windows forms application visual studio Bitmap, my goal is to clear all drawings when I press the push button (make the background clear) The Following code is not exactly what my original code but this is how I created each drawing
Rectangle area;
Bitmap creature;//this only one drawing but I have several
Graphics scG;
Bitmap background;
private void Form1_Load(object sender, EventArgs e)
{
background = new Bitmap(Width, Height);
area = new Rectangle(50, 50, 50, 50);
creature = new Bitmap(@"C:\Users\Desktop\Image.png");
}
public Bitmap Draw()
{
Graphics scG = Graphics.FromImage(background);
scG.DrawImage(creature, area);
return background;
}
}
private void Button_Click(object sender, EventArgs e)
{
// I want to clear all the drawings by push this button
}
Upvotes: 0
Views: 237
Reputation: 3134
There is no way to remove things drawn on a bitmap.
Why don't just dump the old background
bitmap and create a new one?
Upvotes: 1
Reputation: 375
this is duplicate , see this link : How to delete a drawn circle in c# windows form?
or test these Code :
Graphics.Clear();
or
Control.Invalidate();
or
this.Invalidate();
Upvotes: 0
Reputation:
The real way is to use event Paint:
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(creature, area); // draw your image here...
}
To delete, just do nothing in Form1_Paint, and call Refresh();
Upvotes: 0