Remove Panels

Posted on 2005-05-01
Last Modified: 2010-04-16
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;
Question by:madmare
    LVL 22

    Accepted Solution

         for (int i =pictureBox2.Controls.Count -1 ;i >=  0; i --)
                if (pictureBox2.Controls[i]is Panel)
                      pictureBox2.Controls.Remove(pictureBox2.Controls[i]);                                    }                        
    LVL 22

    Expert Comment

    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

    Author Comment

    thnx mnasman
    LVL 22

    Expert Comment

    glad to help :-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now