• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

Remove Panels

hi all,
 i wrote a code that in each time the user press on Button my program add a Panel on a PictureBox, how do i Remove all the Panels that  the user add

Panel p1 = new Panel();
p1.Top = left_dise_click_Y(e.Y);
p1.Left = left_dise_click_X(e.X)+1;
p1.Width = Convert.ToInt16(textBox3.Text)*DisesX-1;
p1.Height =Convert.ToInt16(textBox4.Text)*DisesY-1;
p1.BackColor = Color.Yellow;
pictureBox2.Controls.Add(p1);
0
madmare
Asked:
madmare
  • 3
1 Solution
 
Mohammed NasmanSoftware DeveloperCommented:
     for (int i =pictureBox2.Controls.Count -1 ;i >=  0; i --)
      {
            if (pictureBox2.Controls[i]is Panel)
            {
                  pictureBox2.Controls.Remove(pictureBox2.Controls[i]);                                    }                        
      }
0
 
Mohammed NasmanSoftware DeveloperCommented:
also if you adding panel ad design time and runtime, and would only remove the panel you added at runtime
you could use Tag property to add value for the panels at runtime, and test if the value exist to remove the panel
0
 
madmareAuthor Commented:
thnx mnasman
0
 
Mohammed NasmanSoftware DeveloperCommented:
glad to help :-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now