C# Not Disposing controls like I told it to

后端 未结 4 994
时光取名叫无心
时光取名叫无心 2021-01-26 21:34

I have a Panel control. And inside the panel users can add combobox\'s, textbox\'s labels etc and drag them around and stuff, and there\'s a Delete button on my form where if th

4条回答
  •  离开以前
    2021-01-26 22:05

    A simpler way to delete all your controls is to do this:

    panel.Controls.Clear();
    

    Edit: thanks to Pieter and Paolo, just calling Clear() like this will leak memory since the controls are not disposed, so this is not a good practice.

提交回复
热议问题