Overview of MDI Applications

function OpenWin(url, w, h) { if(!w) w = 400; if(!h) h = 300; window.open(url, "_new", "width=" + w + ",height=" + h + ",menubar=no,toobar=no,scrollbars=yes", true); } function Print() { window.focus(); if(window.print) { window.print(); window.setTimeout('window.close();',5000); } }
Team-Fly    

Special Edition Using Microsoft® Visual Basic® .NET
By Brian Siler, Jeff Spotts
Table of Contents
Chapter 15.  Multiple Document Interface (MDI) Applications


Many of the applications that you create in Visual Basic consist of a series of independent forms, like the ones shown in Figure 15.1. Each of these forms is displayed separately on the screen and is moved, maximized, or minimized separately from any other form. With this type of interface, you cannot easily organize the forms or deal with them as a group. Even with this limitation, this interface is a good one to use for many programs and is probably the most prevalent interface design.

Figure 15.1. This program's user interface consists of two forms that appear to have no visual relationship to each other.

graphics/15fig01.gif

An alternative to this standard interface is the Multiple Document Interface. Forms in an MDI application have a parent/child relationship, which is controlled through form properties. An MDI application has one or more parent forms that contain most (or all) of the other forms in the program. Other forms can be child forms, which are contained within the parent, or standard forms, which are not. With an MDI application, you can easily organize all the child forms or minimize the entire group of forms just by minimizing the parent form.

Microsoft Excel is a familiar example of an MDI application. If you have worked with Excel, you know that you can open multiple windows in the program, access them easily from the menu, and minimize the whole thing with a single click of the mouse. Figure 15.2 shows three blank workbooks opened simultaneously in Excel as an example of a typical MDI application. The Visual Studio .NET interface itself is another example of the MDI style.

Figure 15.2. MDI applications let you manage multiple document windows with ease.

graphics/15fig02.gif

Because the easiest way to learn MDI is by example, we will spend the bulk of this chapter creating a sample program as we explain important MDI concepts. The sample program will use a parent form and a template child form to create a simple text editor program similar to Windows Notepad, with one major improvement the ability to have multiple documents open simultaneously inside the program's interface, rather than having to open multiple instances of the program, as you must do with Notepad.

The multiple-form text editor program you create in this chapter will consist of two forms an MDI parent form and a template for MDI child forms. The user can create a new text document or open an existing one from a file on disk; in either case, a new instance of the child form template is created to contain each document. The application will also include the ability to save and print a document.

First, though, you need to understand how parent and child windows work.

Note

If you're a Visual Basic 6 veteran, you may be interested to note that MDI parent forms are no longer a separate class. Instead, any standard Windows form can be made into an MDI parent form by setting its MDIParent property to True, as you will see in the following. Also, to create a child form, you now set a standard form's MDIP arent property to the form that will serve as its parent; this technique replaces the MDIChild property. This new strategy allows you to have multiple MDIParent forms in one application.


MDI Parent Forms

An MDI parent form is a standard Windows form whose properties have been modified slightly. Several characteristics define a typical MDI parent form:

  • An MDI parent form acts as a container for child forms; that is, the child forms are drawn inside the confines of the parent forms.

  • The parent form automatically provides scrollbars if one or more child forms are positioned outside the visible area of the parent.

  • The MDI parent window and all child windows are represented by a single icon on the Windows taskbar. If the parent form is minimized and then restored, all the child forms are returned to the same layout as they had before the application was minimized.

To create an MDI parent form, you simply set the IsMDIContainer property of a standard Windows form to True. When you create a child form (at runtime), you set the MDIParent property of the new form instance to the name of the MDI parent form, and the child form will be displayed within the parent window.

MDI Child Forms

Just as MDI parent forms have characteristics that define their behavior, MDI child forms also behave in a certain way. The characteristics of an MDI child form are as follows:

  • Each child form is displayed within the confines of the parent form. A child form cannot be moved outside the boundaries of the MDI parent form.

  • When a child window is minimized, its icon is displayed in the parent window, not on the Windows taskbar.

  • When a child form is maximized, it fills the entire inner area of the parent form. Also, the parent form's title bar contains the Text properties of both the parent and maximized child forms, with the child form's Text property being enclosed in square brackets after the Text property of the parent; for example, Text of Parent Form [Text of Child Form].

  • When one child form is maximized, all other child forms are maximized as well.

To create an MDI child form, you create an instance of a form at runtime and set that form's MDIParent property to the Name property of an MDI parent form before showing it.

Note

After the MDIParent property of a form has been set to make it a child form, that form's IsMDIChild property is automatically set to True.



    Team-Fly    
    Top
     



    Special Edition Using Visual Basic. NET
    Special Edition Using Visual Basic.NET
    ISBN: 078972572X
    EAN: 2147483647
    Year: 2001
    Pages: 198

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net