Results 1 to 3 of 3

Thread: last MDI child form closed

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    Scotland
    Posts
    184

    Question last MDI child form closed

    I've a VB.NET MDI application in which I use Menus to allow the user to open Child forms like this:

    Dim NewMDIChild As New frmMyChildForm
    NewMDIChild.MdiParent = Me
    NewMDIChild.StartPosition = FormStartPosition.CenterScreen
    NewMDIChild.Show()

    I also have a SplashScreen as a Child form that is opened with the MDI form, and which I close when any other Child form is opened.

    The problem is this: How do I know when to show the splash form again?

    I have tried various events of the Parent to count the number of childeren, but cannot get this to work. Activate just fires at wrong time, gotFocus is no use either.

    any ideas?

  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    You could add an eventhandler to each child when it's opened.

    VB Code:
    1. Dim NewMDIChild As New frmMyChildForm
    2. NewMDIChild.MdiParent = Me
    3. NewMDIChild.StartPosition = FormStartPosition.CenterScreen
    4. NewMDIChild.Show()
    5. AddHandler NewMDIChild.Closed, AddressOf ChildClosed
    6.  
    7.  
    8. Private Sub ChildClosed(ByVal sender As Object, e As EventArgs)
    9. 'Check ActiveMdiChild or MDIChildren.Length to determine wether to show Splash
    10. End Sub
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    While this does work, it only works if you test your child length to equal 1:
    VB Code:
    1. Private Sub DecrementChildren(ByVal sender As Object, ByVal e As EventArgs)
    2.         If Me.MdiChildren.Length = 1 Then
    3.             frmSplash = New frmProperties
    4.             frmSplash.Show()
    5.         End If
    6.     End Sub

    This code will show the spalsh form but resluts in an unreleased object reference that prevents your mdi form from unloading. Still looking into it.

    I am guessing that some form of Interface will probably be of use here.
    Whadayamean it doesn't work....
    It works fine on my machine!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width