MDI Forms

The Basics

MDI, which stands for Multiple Document Interface, is a system whereby one form "contains" many subforms. Think of a word processor: the main program (a form), can have many documents (other forms) open at one time.

To do this in VB is actually very simple. Start with a new project and select the Project menu. One of the options is "Add MDI Form"; select that.

The MDI form will act as your main form, and you can manipulate it much like any other form. Now go back to the other form (the regular one), set its MDI Child property to True, and change its name to frmChild (for the purposes of this example). Now add a menu item, something like File -> New, and put the following code in it:

Dim frm As New frmChild
frm.Show

Now every time you click File -> New in your project, you'll get a new child window!

You can modify your child form however you want, just like you're used to.

Advanced Stuff

Now for some interesting quirks about the MDI interface.

First off, MDI forms have a lot of control over their child windows. In fact, each MDI form has an Arrange procedure that will re-arrange the windows:

vbCascade, vbTileHorizontal, etc. are all built-in Visual Basic constants.

Here's something else of note: if you take one of the menus on your MDI form and make its WindowList property checked (in the Menu Editor), that menu will display a list of all the child windows that are currently open.

Another interesting thing is that, if you add menus to a child form, those menus will appear on the parent form whenever that child form gets focus. Play around with this until you get an idea as to how it works.


Visual Basic by Example is hosted by GeoCities
1