MDI Child Form Reference Invalid 
Author Message
 MDI Child Form Reference Invalid

How do I recognize when a reference to a MDI Child form in
the MDI container is not logner valid - it isn't NOTHING?
My code is basically;
    If (m_frmLocate Is Nothing) Then
        m_frmLocate = New frmLocate()
    End if
    m_frmLocate.MdiParent = Me  
    m_frmLocate.Show() ' Non-Modal!
The first time through, no problem - the form is New'ed
and shown. Subsequent times through, if the form is hidden
it is shown, but if it was closed, I get an exception. But
not on the "Is Nothing" or the setting "MdiParent" - on
the "Show". Any help is appreciated.


Fri, 23 Sep 2005 12:57:02 GMT  
 MDI Child Form Reference Invalid
Hello Mike,


Quote:
> How do I recognize when a reference to a MDI Child form in
> the MDI container is not logner valid - it isn't NOTHING?
> My code is basically;
>     If (m_frmLocate Is Nothing) Then
>         m_frmLocate = New frmLocate()
>     End if
>     m_frmLocate.MdiParent = Me
>     m_frmLocate.Show() ' Non-Modal!
> The first time through, no problem - the form is New'ed
> and shown. Subsequent times through, if the form is hidden
> it is shown, but if it was closed, I get an exception. But
> not on the "Is Nothing" or the setting "MdiParent" - on
> the "Show". Any help is appreciated.

Set the reference in m_frmLocate to Nothing when the form is closed:

\\\
Private myform As Form2

Private Sub Button1_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs _
) Handles Button1.Click
    If myform Is Nothing Then
        myform = New Form2()
        'myform.MdiParent = Me
        AddHandler myform.Closed, AddressOf Me.ChildForm_Closed
        myform.Show()
    Else
        MsgBox("Form already open: " & myform.Text)
    End If
End Sub

Private Sub ChildForm_Closed( _
    ByVal sender As Object, _
    ByVal e As System.EventArgs _
) Handles MyBase.Closed
    myform = Nothing
End Sub
///

Regards,
Herfried K. Wagner



Fri, 23 Sep 2005 14:32:38 GMT  
 MDI Child Form Reference Invalid
Thanks Herfried. That's a nice OO solution.


Sat, 24 Sep 2005 00:57:37 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Make a reference to a MDI form with a reference of a MDI child form

2. Q: Form activate Fires On Non Child MDI Forms But Only Once On Child Mdi Forms

3. MDI Form with MDI Child in referenced DLL

4. Referencing MDI Child forms?

5. Modifying object in MDI Parent form from MDI Child form

6. MDI-Child form and positon on MDI-form

7. Developing OLE MDI Child forms displayed on Control MDI Form

8. MDI child forms on top of a picture on a MDI form

9. Help with MDI Forms and MDI child forms

10. Modal non MDI forms and Modeless MDI child forms in VB 5.0

11. Allow MDI Child form to overlap Aligned Picture Box in MDI Form

12. Having MDI form with MDI Child form in DLL

 

 
Powered by phpBB® Forum Software