Re: me.close vs me.dispose
I suggest that you read the documentation for the Form.Close method. It explains when closing a form disposes it and when it doesn't.
Re: me.close vs me.dispose
Form.Close Method
Quote:
Originally Posted by MSDN
The two conditions when a form is not disposed on Close is when (1) it is part of a multiple-document interface (MDI) application, and the form is not visible; and (2) you have displayed the form using ShowDialog. In these cases, you will need to call Dispose manually to mark all of the form's controls for garbage collection.
Re: me.close vs me.dispose
I see. I thought you were supposed to show new forms with ShowDialog? It seems like that's not the case since me.close doesn't work with ShowDialog?
Dave
Re: me.close vs me.dispose
ShowDialog won't let you switch to other forms while you are showing a form using this method, there is also the Show method. When using ShowDialog all the codes that follows it until the the form is not closed. You can use Me.Close in the form shown using ShowDialog, why did you say that it doesn't work?
Re: me.close vs me.dispose
Quote:
Originally Posted by daviddoria
I see. I thought you were supposed to show new forms with ShowDialog? It seems like that's not the case since me.close doesn't work with ShowDialog?
Dave
ShowDialog displays a form as a modal dialogue. If you want your form displayed as a modal dialogue then you're supposed to display it with ShowDialog. If you don't want your form displayed as a modal dialogue then you're not supposed to display it with ShowDialog.
Of course Me.Close works with modal dialogues. It does exactly what it's supposed to do: it closes the form. It doesn't dispose it because it's not supposed to dispose it. Calling Me.Close in a modal dialogue, i.e. a form that has been displayed with ShowDialog, is equivalent to setting the DialogResult property to Cancel: the form is dismissed and ShowDialog returns Cancel.
Re: me.close vs me.dispose
A good way to make sure that you are disposing a form shown in dialog mode is to use the following code structure:
Code:
Dim result As DialogResult
Using frm1 As New Form1
result = frm1.ShowDialog()
End Using
The using statement is very good because it will handle the disposal of any object that implements the IDisposable interface, which all forms do by default.