locked
Nothing keyword in VB RRS feed

  • 問題

  • Hi

     

    If I opened Form2 from within Form1, see example code below:

     

    Dim Frm As New Form2

    If Windows.Forms.DialogResult.OK = Frm.ShowDialog() Then

    ....

    ....

    ....

    End If

     

    Form2 is then closed (with Me.Closed in Form2), is it neccessary to have this code as shown below?

     

    Frm = Nothing

     

     

    Thanks.

     

     

     

     

     


    2008年10月9日 10:07

解答

  • Hi Larry,

    I think you need to use the code
    Frm.Dispose() or Frm = Nothing
    to mark all the form;s controls for garbage collection, as you are using ShowDialog to display you Form2

    Please read the URL below.
    According to the Microsoft website said:
    <<

    When a form is closed, all resources created within the object are closed and the form is disposed. You can prevent the closing of a form at run time by handling the Closing event and setting the Cancel property of the CancelEventArgs passed as a parameter to your event handler. If the form you are closing is the startup form of your application, your application ends.

    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.

    >>

    Please find the URL below:
    http://msdn.microsoft.com/en-us/library/system.windows.forms.form.close.aspx

    Please correct me if my concept is wrong.

    Hope this help.


    2008年10月9日 15:05