How to Use the Forms Collection to Unload All MDI Child FormsLast reviewed: June 21, 1995Article ID: Q97620 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0
SUMMARYYou can use Visual Basic code to close all MDI children by using the forms collection. The forms collection contains references to all forms -- the MDI parent form, MDI children forms, and non-MDI forms. To unload or close all MDI forms, loop through the forms collection testing the value of the MDIChild property on each form. If the MDIChild property is true, unload the form.
MORE INFORMATION
Steps to Create Example1. Start Visual Basic or from the File menu, choose New Project (ALT, F, N)if Visual Basic is already running. Form1 is created by default.
Caption Name Indent ------------------------------ File mFile no New mNew once Close All mCloseAll once Dim ChildCount As Integer
Sub mNew_Click () Dim newWindow As New Form1 ChildCount = ChildCount + 1 newWindow.Caption = "Child " & Str$(ChildCount) newWindow.Show End Sub
Sub mCloseAll_Click () i = 1 Do While i < Forms.Count If forms(i).MDIChild Then ' *** Do not increment i% since a form was unloaded Unload forms(i) Else ' Form isn't an MDI child so go to the next form i = i + 1 End If Loop ChildCount = 0 End Sub children. |
Additional reference words: 2.00 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |