Removing dynamically created controls in C#

后端 未结 5 1430
抹茶落季
抹茶落季 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:26

    It seems Hans Passant forgot a very important detail, too (or perhaps he was just adding to the existing answers, not submitting a full answer). At any rate, here's what I had to do both to invisiblize and dispose my dynamic controls:

    Panel p = tp.Controls[panelName] as Panel;
    p.Controls.Clear();
    for (int i = 0; i < p.Controls.Count; i++)
    {
        p.Controls[i].Dispose();
    }
    

提交回复
热议问题