Form Count in MDI App

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Chris Lane (anonymous_at_discussions.microsoft.com)
Date: 03/24/04


Date: Wed, 24 Mar 2004 06:26:06 -0800

Hi,

Ok here goes I have an MDI application and when a user clicks on the close button on the form "the X" , I would like to disable menus if there are no more MDI Chid forms. So I decided to raise an event from the MDI Child form to the parent, allowing the parent to disable menus if it has no more MDI Child Forms. This works fine if I only create one child form but when there are anymore then that the count shows that there is one more then should be untill the GC comes to get it.
I have tried raising this event from the closing, closed and disposed events of the Child form.

Does anybody have any idea how I can force an accurate count of MDI Child forms?

Here is the code:

 Dim frm As Form
        Dim Count As Integer
        For Each frm In Me.MdiChildren
            Count = Count + 1
        Next
        If Not mnuReportClose.Enabled = True Then
            mnuReportClose.Enabled = True
        End If
        If Not mnuWindow.Enabled = True Then
            mnuWindow.Enabled = True
        End If
        If Count < 1 Then
            mnuReportClose.Enabled = False
            mnuWindow.Enabled = False
        End If

Thanks


Quantcast