What is an MDI form?
MDI stands for Multiple Document Interface. You have probably seen many MDI applications. When you want to handle multiple documents, MDI forms are useful in a Windows program.
How to add an MDI form to the current project?
Project -> Add MDI form. Click Project from the menu bar, and click Add MDI form. It's simple! Remember, a project can have only one MDI form.
Restrictions of the MDI form
- You can have only one MDI form per project.
- You can't place most controls on an MDI form. The only controls that can be placed on the surface of the MDI form are Menus, Timer, CommonDialog, PictureBox, ToolBar, and StatusBar.
How does the MDI form work?
There can be only one MDI parent form in a project with one or more MDI child forms (or simply child forms).- MDI child form: To add a child form, you have to add a regular form, and set the MDIchild property to True. You can have many child forms and can show an MDI child form using the Show method.
- AutoShowChildren property of an MDI form: The default value of the AutoShowChildren property is True. When it is True, the MDI child forms are displayed once they are loaded. When the value is False only then you can keep it hidden after loading, otherwise not.
- Restrictions of the MDI child forms:
2. You can't display a menu bar on the MDI child form.
Now coming to the point - how the MDI form works. The parent form contains a menu bar on top of it. From there, the user opens or creates a new document. In this way, the user accomplishes his/her work in one or multiple documents, then saves and closes the document (form). You can create instances of a single form in the code using the Set keyword (Using the object variables).
'Inside the MDIForm module
Private Sub mnuFileNew_Click()
Dim frm As New Form1
frm.Show
End Sub
- ActiveForm property: This is the Object type read-only property of the MDI form. You can apply this property to one of the children. For example, you can close the active form using this property from the Close menu command of the menu bar.
'In the MDI form
Private Sub mnuFileClose_Click()
If Not (ActiveForm Is Nothing) Then Unload ActiveForm
End Sub
Sample program
Download the sample program to understand how to work with MDI forms in Visual Basic 6. Download it.