Simple question...
I have controls that the user can drag around on my form at runtime. And they can also delete them... Should I just Call .Dispose();
when they click the delete button, or should I do something like panel1.Controls.Clear(Control);
? ...Or something else?
Thanks :)
Bael
You should remove it from the parent Controls collection as described in Darin Dimitrov's response, and also call Dispose:
panel.Controls.Remove(someControlInstance);
someControlInstance.Dispose();
You should always call Dispose on objects that implement IDisposable when you have finished with them, so that any unmanaged resources they own are immediately released.
Just remove the control from the panel:
panel.Controls.Remove(someControlInstance);
Once there are no more references to it, it will be subject to garbage collection and unmanaged resources will be properly disposed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With