|
-
Jan 7th, 2009, 06:24 PM
#1
Thread Starter
Hyperactive Member
me.close vs me.dispose
I find that if I do me.close and then reopen the form with showDialog later, things are as they were before I closed it. If I use me.dispose and then later open the form again, its as if it was never opened before.
Are these two both valid methods for leaving a form?
Thanks
Dave
-
Jan 7th, 2009, 06:43 PM
#2
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.
-
Jan 8th, 2009, 08:59 AM
#3
Re: me.close vs me.dispose
Form.Close Method
 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.
-
Jan 8th, 2009, 09:02 AM
#4
Thread Starter
Hyperactive Member
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
-
Jan 8th, 2009, 09:12 AM
#5
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?
-
Jan 8th, 2009, 09:14 AM
#6
Re: me.close vs me.dispose
 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.
-
Jan 8th, 2009, 09:56 AM
#7
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|