Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

 

I've got a MDIParent Form (frmMain) from which I launch a MDIChild Form (frmMDI_1).

 

Now I want to launch the second MDIChild Form (frmMDI_2) from within the first MDIChild Form. The MDIParent of the second MDIChild Form should also be frmMain.

 

I tried to do this as shown below

 

'Inside a Module
Public WithEvents MainForm As frmMain
Public WithEvents Child1 As frmMDI_1 
Public WithEvents Child2 As frmMDI_2

'Inside the frmMDI_1 Form
Child2 = New frmMDI_2

With Child2
   .MdiParent = MainForm
   .Show()
   .WindowState = FormWindowState.Maximized
End With

 

When the code above is ran the frmMDI_2 Form is not shown as a MDIChild but as a normal form. What am I doing wrong?

 

Thanks

Posted

Could you signal the MDIParent Form from the first MDIChild Form with a custom method within the MDIChild?

Class frmMain

 Public Function ParentShow(nForm as Integer) As Integer
   If (nForm = 1) Then
     If (Child1 Is Nothing) Then
       Child1 = New frmMDI_1
       With Child1
         .MdiParent = MainForm
         .WindowState = ForWindowState.Maximized
         .Show()
        End With
        Return 1 ' Can be interpreted as a True
     Else
       Return 0 ' Can be interpreted as a False
     End If
   Else If (nForm = 2) Then
     If (Child2 Is Nothing) Then
       Child2 = New frmMDI_2
       With Child2
         .MdiParent = MainForm
         .WindowState = ForWindowState.Maximized
         .Show()
        End With
        Return 1 ' Can be interpreted as a True
     Else
       Return 0 ' Can be interpreted as a False
     End If
   Else
     Return -1 ' Signal an error
   End If
 End Sub

End Class

Also, you may want to play around with the order that you call Show() and WindowState. I had some problems with them recently where I was attempting to hide an application in the task bar tray, and it turned out I wasn't calling the methods in the right order. It wasn't documented anywhere that I could find, though.

 

Hope this helps.

Posted

This is very odd. When I made a new project and used code simular to the code above it worked fine. But in my excisting project it still doesn't work.

 

I've attached the test project to this post.

mdi_test.zip

Posted

They seem to be valid.

 

MDIParent = {PROJECTNAME.frmMain}

 

When I display a MsgBox after the Show method it also shows the right MDIParent (frmMain).

 

With MDI_1
   .MdiParent = Me
   .Show()
   .WindowState = FormWindowState.Maximized

   MsgBox(.MdiParent.Name)
End With

Posted
Shouldn't you be creating a new instance of the form?
MDI_1 = New frmMain()
With MDI_1
 .MdiParent = Me
 .Show()
 .WindowState = FormWindowState.Maximized
 MsgBox(.MdiParent.Name)
End With

 

Yes that's right. I forgot to paste that part into this post.

Posted

I've found the problem. Before the MDIParent form is being shown the user has to log in. This is done using a loginform.

 

In the properties of the project I set that loginform as startup form, and I changed the option Shutdown Mode to When Last Form Closes.

 

After I changed these settings in the test project that I attached to this post no MDI form was shown when the button was clicked.

 

The code used to show the MainForm from inside the LoginForm is like the one below.

 

Dim frm As New frmMain

frm.Show()

Me.Close

 

Yet when I change that code to this

 

frmMain.Show()

Me.Close

 

it works. Although very happy that it finally works, I'm quite curious to why it didn't work using the first method of showing the MainForm.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...