• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

Trying to Get MDIParent to run a sub after it see's NO MDIChild forms present(open)

I have a MDIParent which needs to be able to see when all the MDIChild Forms have been Closed so that I may run a sub process.  Any ideas.
Oh, I am pretty new at VB, so some code example may help.

Thanks.
0
danorme
Asked:
danorme
  • 2
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
What version VB?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
(assuming VB.net based on your question history)


For VB.Net 2005:

    Public Class MdiParent
 
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim f1 As New Form1
            f1.MdiParent = Me
            AddHandler f1.FormClosed, AddressOf MdiChild_FormClosed
            f1.Show()
        End Sub

        Private Sub MdiChild_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs)
            CType(sender, Form).Dispose()
            If Me.MdiChildren.Length = 0 Then
                NoChildrenLeft()
            End If
        End Sub

        Private Sub NoChildrenLeft()
            Debug.WriteLine("No Children Left")
        End Sub

    End Class



For VB.Net 2003 and below:

    Public Class MdiParent
        Inherits System.Windows.Forms.Form

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim f1 As New Form1
            f1.MdiParent = Me
            AddHandler f1.Closed, AddressOf MdiChild_Closed
            f1.Show()
        End Sub

        Private Sub MdiChild_Closed(ByVal sender As Object, ByVal e As System.EventArgs)
            CType(sender, Form).Dispose()
            If Me.MdiChildren.Length = 0 Then
                NoChildrenLeft()
            End If
        End Sub

        Private Sub NoChildrenLeft()
            Debug.WriteLine("No Children Left")
        End Sub

    End Class
0
 
EDDYKTCommented:
if vb6

add this routine to module

Public Sub showlastformMsg()
   
    If Forms.Count = 2 Then
        MsgBox "last mdi child closed"
    End If
End Sub

add this on each mdi child

Private Sub Form_Unload(Cancel As Integer)
showlastformMsg
End Sub
0
 
EDDYKTCommented:
may be you want to hide the form before

Private Sub Form_Unload(Cancel As Integer)
Me.Hide
showlastform
End Sub
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now