Removing dynamically created controls in C#

后端 未结 5 1427
抹茶落季
抹茶落季 2020-11-27 18:33

I have a program that adds a series of \"blips\" to a graph:

PictureBox blip = new PictureBox();
blip.Location = new Point(blipHours, blipAltitude);
blip.Siz         


        
5条回答
  •  臣服心动
    2020-11-27 19:25

    This will remove all of the PictureBox controls from the particular container (i assume a graph in your case).

     for (int i = this.Controls.Count - 1; i >= 0; i--)
                {
                    PictureBox control = this.Controls[i] as PictureBox;
                    if (control == null)
                        continue;
    
                    control.Dispose();
                }
    

提交回复
热议问题