Ensure the form is disposed

O

osmarjunior

How to ensure that a form is disposed?
When I work with modal forms I do the following:

using (Form1 frm = new Form1())
{
frm.ShowDialog();
}

As far as I read, when it ends the using scope, the form is disposed.
But if I don't use modal forms, like this:

Form1 frm = new Form1();
frm.Show();

In this case, when the user clicks on the X button, or a close button,
the form is disposed?

Junior.
 
N

Nicholas Paldino [.NET/C# MVP]

Junior,

Yes, when the user clicks on the close button, the form is disposed of.
When the message to close is received for the form, it calls Dispose.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top