Dispose not called?!

  • Thread starter Thread starter joe
  • Start date Start date
J

joe

Hi,

If I have a form and I show it like this:

MyForm f=new MyForm();
f.Show();

when I close the form by clicking the close button
MyForm.Dispose() is called.
When I show the form like this:

f.ShowDialog();

MyForm.Dispose() is not called. Is this a bug or there is
a reason for this behaviour?

Thanks
 
Hi joe,

There is a reason.
When you close modal forms (ShowDialog) you normally want to retrieve some
properties from the form.
That's why form is not automatically disposed - it is up to you to dispose
it.
The same isn't true for the nonmodal forms - so they are automatically
disposed.

HTH,
 
Back
Top