December 5, 1995
This article explains how to design your Microsoft® Visual Basic® application so that after the user closes one child form on the screen the remaining child forms are automatically cascaded.
When you design a Microsoft® Visual Basic® application in which one form contains several child forms, the user can selectively close a child form to remove it from the screen. However, when you close a child form in this manner, its space is still occupied in the multiple document interface (MDI) form. You can use the Arrange method to automatically cascade all remaining child forms each time a child form is closed or unloaded from memory.
This program shows how to arrange child forms in a cascading format whenever child forms are loaded or unloaded.
Private Sub Form_Unload(Cancel As Integer)
MDIForm1.Arrange 0
End Sub
Private Sub NewForm_Click()
Static X
Dim Form As New Form1
X = X + 1
Form.Caption = "Child" & X
MDIForm1.Arrange 0
End Sub
Run the example program by pressing f5. Click several times on the New Form menu. Each time you click this menu entry, a new child form is created, with each form being named sequentially as Child1, Child2, and so on. When you click the Close button, the child form is unloaded, and the remaining child forms are arranged in a cascading fashion, with no blank positions where the unloaded child forms used to appear.