Search code examples
vb.netmdimdichildmdiparent

How to call MDIParent from windows form?


I have an MDI form called "MDIParent1", MDI child form "MDIChild1" and I have a windows form called "FrmTest".

Now there is a button called "btnTest" in "MDIChild1" form and here is the click event.

Dim V As New FrmTest
    V.MdiParent = MDIParent1
    V.Show()

But It couldn't load the "frmTest" form. Is there any another way to do so? Thanks in advance.


Solution

  • Try This :

        Dim V As New FrmTest
        V.MdiParent = Me.MdiParent
        V.Show()
    

    The above assumes that MDIChild1.MdiParent is already set to MDIParent1

    You could also do this :

        Dim V As New FrmTest
        V.MdiParent = Application.OpenForms("MDIParent1")
        V.Show()
    

    To close other forms, iterate through MdiChildren collection :

        Dim MyMdiForm as Form = Application.OpenForms("MDIParent1")
    
        For Each Frm As Form In MyMdiForm.MdiChildren  
    
              If Frm IsNot V Then
    
                    Frm.Close()
    
              End If
    
         Next