I want to make Windows Forms controls readonly and IDisposable.
Is this is a good thing or a bad thing and what do I have to watch out for when calling Dispose?
I have a Tab (PageTab) that I extend and insert a Panel which has a listview and another Toolbar control into. These tabs then get inserted into a tab control (all native .NET Windows Forms controls).
When the user closes one of these tabs I call the Dispose method (which follows the MSDN way of implementing IDisposable).
Is it wise or suggested to declare the controls as read-only (see below)?
protected readonly ListView _AccountsList = new ListView();
protected readonly Panel _Panel = new Panel();
Because in the Dispose method I just call _Panel.Dipose()
, etc. on them, but I cannot set them to null. I want to avoid leaks as much as I can and have things garbage collected.
What's the best way for a non-Designer GUI development and disposing them?