One correction: For Non-modal forms Dispose is called when the form is
closed. For modal forms Dispose is not called and so you have to call it
explicitly
mark

-----Original Message-----
From: Ian Griffiths [mailto:[EMAIL PROTECTED]] 
Sent: Saturday, April 13, 2002 4:04 PM
To: [EMAIL PROTECTED]
Subject: Re: [DOTNET] Components, Designer and Dispose

If the component is being dragged on to the form from the toolbox, all
you
need to do is supply a constructor that takes an IContainer.  If you
then
make that constructor call IContainer.Add, passing itself as the
parameter,
this will result in your component being added to the 'components'
member of
your form.  The components member is disposed of in the Dispose method
of
your class, and it will in turn dispose of any component that it
contains.

The Forms Designer will automatically use such a constructor if
available
when it constructs a component.  So any components on your form that
supply
such a constructor will automatically have Dispose called when the form
itself is Disposed.

There are two caveats:  (1) this is only automatic if the component was
dragged onto the form from the toolbox, and (2) your component will only
have its Dispose called if something calls Dispose on the form.  (That
doesn't happen automatically when the form is closed - you are allowed
to
reopen a form after closing it, so disposal only happens if something
calls
Dispose explicitly.)


--
Ian Griffiths
DevelopMentor

----- Original Message -----
From: "Axel Heitland" <[EMAIL PROTECTED]>

I've implemented a simple component-derived class which is hosted on a
windows form.

For successfull shutdown the component needs a call to it's Dispose
method at the end of it's lifetime; unfortunately the WinForms designer
doesn't generate that code automatically so my users need write that
code manually (and they forget all the time and are shouting at me ;-))

Is there any way to tell the winforms designer to generate the dispose
code for me automatically ?!

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to