VB6 Tutorial 63: MDI Forms
This lesson discusses how to work with MDI forms in Visual Basic 6. A sample program has been given at the end of this lesson to enable the learners to quickly understand the concepts of MDI forms.
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?
From the top line menu, select Project -> Add MDI form. It's simple!
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.
- These restrictions are there because MDI forms are the special type of forms, especially used to handle multiple child forms.
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
- You can't display an MDI child form outside its parent.
- 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
QuickHint:
Note that '(ActiveForm Is Nothing)' represents that there is no active form. The 'Not' keyword before it negates the value.
Loading Comments ...
Comments
dwirch posted this comment on 2020-03-25:
What's the output you trying to share? I don't see anything.
AnonymousCoward posted this comment on 2020-04-22:
Visual Basic automatically associates this new Form with the parent Form. This child Form can't exist outside the parent Form; in the words, it can only be opened within the parent Form.AnonymousCoward posted this comment on 2020-04-22:
The parent Form may not contain any controls. While the parent Form is open in design mode, the icons on the ToolBox are not displayed, but you can't place any controls on the Form. The parent Form can, and usually has its own menu. Make this Form as child of MDI Form by setting the MDI Child property of the SDI Form to True. Set the caption property to MDI Child window.AnonymousCoward posted this comment on 2020-04-23:
An MDI application must have at least two Form, the parent Form and one or more child Forms. Each of these Forms has certain properties. There can be many child forms contained within the parent Form, but there can be only one parent Form.AnonymousCoward posted this comment on 2020-04-23:
At design time double click on MDI Open and add the following code in the click event of the open menu.AnonymousCoward posted this comment on 2020-04-24:
MDI Form cannot contain objects other than child Forms, but MDI Forms can have their own menus. However, because most of the operations of the application have meaning only if there is at least one child Form open, there's a peculiarity about the MDI Forms. The MDI Form usually has a menu with two commands to load a new child Form and to quit the application. The child Form can have any number of commands in its menu, according to the application. When the child Form is loaded, the child Form's menu replaces the original menu on the MDI Formdwirch posted this comment on 2020-04-24:
Is it me? or are you reposting the same comments, re-worded?
You must be logged in to make a comment.
AnonymousCoward posted this comment on 2020-03-25:
Before run the application in the project properties set MDI Form as the start-up Form. Save and run the application. Following output will be displayed.