I replaced:
panel.Controls.Clear();
with:
Clear(panel);
Where:
public static void Clear(Control ctrl)
{
while (ctrl.Controls.Count > 0) ctrl.Controls[0].Dispose();
}
And I get the following error: at Application.Run(new Form1());
System.ObjectDisposedException was unhandled
Cannot access a disposed object.
Object name: ‘Label’.
Any idea why that might be?
Thanks.
EDIT:
See How to Clear() controls without causing a memory leak
EDIT: Sorry, I’m probably disposing of something which I just want to remove from its parent. I’ll check that. Thanks for the answers.
I was probably disposing of some
Controls I was using later on in the code.