C# Not Disposing controls like I told it to

后端 未结 4 998
时光取名叫无心
时光取名叫无心 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:03

    Dispose() only cleans up unmanaged resources (although Paul Williams noted in the comments that it is usually more complex than this!) so it may or may not do anything useful in your case.

    Try removing the controls with the RemoveAt(i) method, not Dispose():

    for(int i = panel.Controls.Count-1; i >= 0; i--)
    {
        panel.Controls.RemoveAt(i);
    }
    

提交回复
热议问题