MDI
MDI
MDI
The multiple-document interface (MDI) allows you to create an application that maintains
multiple forms within a single container form. Applications such as Microsoft Excel and
Microsoft Word for Windows have multiple-document interfaces.
An MDI application allows the user to display multiple documents at the same time, with
each document displayed in its own window. Documents or child windows are contained
in a parent window, which provides a workspace for all the child windows in the
application. For example, Microsoft Excel allows you to create and display multipledocument windows of different types. Each individual window is confined to the area of
the Excel parent window. When you minimize Excel, all of the document windows are
minimized as well; only the parent window's icon appears in the task bar.
A child form is an ordinary form that has its MDIChild property set to True. Your
application can include many MDI child forms of similar or different types.
At run time, child forms are displayed within the workspace of the MDI parent form (the
area inside the form's borders and below the title and menu bars). When a child form is
minimized, its icon appears within the workspace of the MDI form instead of on the
taskbar, as shown in Figure 6.4.
Figure 6.4 Child forms displayed within the workspace of the MDI form
3. Click the ellipses () next to the Items property, and click Add to add two child
tool strip menu items. Set the Text property for these items to New and Window.
4. In Solution Explorer, right-click the project, point to Add, and then select Add
New Item.
5. In the Add New Item dialog box, select Windows Form.
This form will be the template for your MDI child forms.
The Windows Forms Designer opens, displaying Form2.
6. From the Toolbox, drag a RichTextBox control to the form.
7. In the Properties window, set the Anchor property to Top, Left and the Dock property to Fill.
This causes the RichTextBox control to completely fill the area of the MDI child form, even when the
form is resized.
8. Double click the New menu item to create a Click event handler for it.
9. Insert code similar to the following to create a new MDI child form when the user clicks
the New menu item.
10.
In the drop-down list at the top of the Properties window, select the menu
strip that corresponds to the File menu strip and set
the MdiWindowListItem property to the Window ToolStripMenuItem.
This will enable the Window menu to maintain a list of open MDI child windows with a
check mark next to the active child window.
11.
Press F5 to run the application. By selecting New from the File menu, you
can create new MDI child forms, which are kept track of in the Window menu item.