Panel clear all

I would like to reset the panel to its original state. For example, I set the image as the background, I drew graphics on a part of the panel. I have to clear everything. How?

+9
source share
5 answers

First you need to clean the panel

panel1.Controls.Clear(); 

then call the initial form.

 panel1.Controls.Add(orig_form); 
+15
source

Use the following code to remove all graphics from the panel

 panel1.Invalidate(); 

If there is something you need to add to the initial state of the panel, then after calling invalidate you will have to install these things again.

If the initial state of the panels requires some graphics or data, you can put this in the graphic event of the panel, so every time a cancellation is called, your panel gets the initial state with these elements.

+3
source

Use the panel1.refresh(); command panel1.refresh(); . It resets the panel to its original state.

+2
source

This is the only solution that worked for me:

 private void button3_Click(object sender, EventArgs e)//Clear button { using (g = Graphics.FromImage(bmp)) { g.Clear(Color.Transparent);//you can choose another color for your background here. panel1.Invalidate(); } } 
+1
source

Here is the SO link that searches for what you want:

Reset winform elements (C # /. Net)

0
source

Source: https://habr.com/ru/post/887786/


All Articles