Controls add/remove and Dispose

  • Thread starter Thread starter Wilfried Mestdagh
  • Start date Start date
W

Wilfried Mestdagh

Hi,

If I add programatically a Panel to a control, and a Label add to that
Panel. Then when I Dispose the Panel do I have to Dispose the Label
also, or does the Panel take care of that ? And if it is do I gain time
doing it myself or not ?

I ask this because if I for example put panels or labels on Mappoint
ActiveX control, and I don't dispose them myself it take a lot of time
to destroy the activeX control. But maybe this is not the truth with
dotNet controls like a panel or label ?
 
Hi Wilfried,

Here's a tip. First, create a Panel in your form. Add a label to it. Then
look at the designer-generated code. All you have to do then is write the
code which does this by essentially copying the designer-generated code.
Whatever it does when it adds the panel and the label, you do the same.
Whatever it does when disposing the form, you do the same.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

The shortest distance between 2 points is a curve.
 
The simplest rule:
If an object implements IDisposable (has a "Dispose" method), then your code
should call that method. Otherwise, "don't worry, be happy".
Peter
 
Back
Top