Results 1 to 5 of 5

Thread: Me.Close or Me.Dispose

  1. #1
    capedech is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Oct 2008
    Posts
    62
    Reputation
    76

    Me.Close or Me.Dispose

    What's the different between Me.Close and Me.Dispose for closing a Form ?
    What I know, Me.Dispose is included in Syntax Me.Close. Am I right ?

    My friend did this to close a Form :
    Me.Close
    Me.Dispose

    Does it necessary ?

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,562
    Reputation
    2737
    Have a look at Form.Close method in help. Notice these remarks:
    Quote Originally Posted by help
    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.

  3. #3
    capedech is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Oct 2008
    Posts
    62
    Reputation
    76
    I see now.
    Thanks, It explain a lot.

  4. #4
    alim's Avatar
    alim is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    bangladesh
    Posts
    89
    Reputation
    111
    but what the difference between those?
    Last edited by alim; 01-04-2009 at 4:59 AM.

  5. #5
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    12,943
    Reputation
    1625
    Quote Originally Posted by alim View Post
    but what the difference between those?
    Basically it means that if you display a form by calling Show then call Close will dispose it, while if you display the form by calling ShowDialog calling Close will not dispose it. That's basically so you can use the same form multiple times as a modal dialogue. If you only want to use a dialogue once then you should create it with a Using block, which will also dispose it:
    Code:
    Using dlg as New DialogueForm
        If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
            'The user clicked OK.
        End If
    End Using 'The form gets disposed here.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking