7.11 Creating MDI Forms

 <  Day Day Up  >  

You want to create a Windows Form that acts as a container for several child forms.


Technique

Using the property browser, set the IsMdiContainer property to true on the form you want to act as the parent form. Create an additional form used as the child form by clicking Project, Add Windows Form from the main menu. To add a new child form within the parent form, create a new child form object and set its MdiParent property equal to the parent object. Because you do so within the parent form class, you can use the this keyword. Finally, call the Show method of the child form to display it:

 
 ChildForm[] childForms = new ChildForm[3]; public Form1() {     InitializeComponent();     for( int i = 0; i < 3; i++ )     {         childForms[i] = new ChildForm();         childForms[i].MdiParent = this;         childForms[i].Show();     } } 

Comments

An MDI application supports several child windows within a main window. MDI applications traditionally allow the editing of several documents within a single main application window. A user can navigate to each document and edit it without having to open and close windows repeatedly. You create an MDI container form, also known as the parent, by setting the IsMdiContainer property to true . When you do this, the form's main area is drawn using a sunken display style with a raised border.

Creating a child window is similar to creating the parent to which it belongs because all you need is a single property change. In the case of the child window, you use the MdiParent property, and its value is a reference to the parent object. Because the creation of child windows occurs within the parent object itself, either through a menu event or some other event, you can simply use the this keyword, as shown in the code listing earlier. In the next few recipes, you'll see how ownership rules apply to forms as well as how parent forms can interact with the child forms they contain.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

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