Search code examples
vb.netmdiparent

Opening a single CHILD in MDI form


I found the following code from stackoverflow

It works correctly when I execute the MDIParent form as the first form in the project

For Each f As Form In Application.OpenForms
  If TypeOf f Is Form1 Then
    f.Activate()
    Return
  End If
Next

Dim myChild As New Form1
myChild.MdiParent = Me
myChild.Show()

I need to open the LOGIN form as the first form and open MDIParent.

If I open the login form as the first form the above code it not working.. Need a solution

I added this code to a button control


Solution

  • Set your Login form as the start form for your project.

    On your button, Show the MDI Form (and close the Login form if you wish)

    MDI_Main.Show()
    Me.Dispose()
    

    Then to open your MDI Child forms, use the following code:

    frmChild.MdiParent = Me
    frmChild.Show()
    

    This is all the code you should need.