After completion of today's lab, you should be able to
Microsoft Windows provides several window management schemes:
Choosing the right scheme requires thinking about the users, their skill levels, the tasks, the display space, etc.
A multiple-document interface contains a single primary window, called the parent, and a set of child windows contained in the parent. It was popularized by Microsoft Word 97 in which a single Word application contains multiple text windows that represent the current documents being worked upon.
The advantages include that the child windows share the parent's interface components like menus, toolbars, and status bars. It provides a logical grouping of objects within the larger context of the desktop. And, it also helps in comparisons between similar types of data in multiple windows.
MDIs have fallen out of favor with interface designers in recent years. One disadvantage with MDIs is the difficulty of rapidly switching from one document to another. Tabbed document interfaces is a popular way of providing the advantages of MDIs along with a quick way to switch between open documents.
With MDI applications, the parent form needs to have its IsMDIContainer property set to True. While you are at it, you can also set the WindowState property to Maximized as it is easiest to manipulate MDI child windows when the parent form is maximized.
Activity: Create a MDI Parent Class
WindowsUI in Solution Lab7MainForm.csMainForm to
TrueWindowState property to MaximizedMainForm and insert the standard menu itemswindowToolStripMenuItem to your menu before the Help menu
MdiWidowListItem property to windowToolStripMenuItem.Child forms in MDI applications are derived from Window's Form class
To add a new window as a MDI child to a MDI application, declare and instantiate the new object in the MDI parent form, set its MdiParent property to the MDI parent object, and then show the form.
ChildForm myChild = new ChildForm(); myChild.MdiParent = this; myChild.Show();
Activity - Create a MDI Child Class
ChildFormChildForm and Dock the RichTextBox in the parent containerMainForm for the New menu item under the File menu to instantiate and show a new ChildFormTo close the current child window, the .NET environment keeps track of the active window in the property ActiveMdiChild
this.ActiveMdiChild.Close();
You can manage the Window layout by using the LayoutMdi method with the Parent object.
this.LayoutMdi(MdiLayout.TileVertical);
The MDI Parent object has a MdiChildren property that provides an array of references to MDI child objects. A possible use of the MdiChildren array is to write a foreach loop to close all the current child windows open.
foreach (ChildForm window in MdiChildren) window.Close();
Activity: Manage your children
When an MDI child form has a MainMenu component and the child form is opened within an MDI parent form that also has a MainMenu component, then the menu items will merge automatically.
Activity: Add an Font Menu to the ChildForm class
ChildForm class to allow the user to change the font face and font sizethis.richTextBox1.Font = new Font(FontFamily.GenericMonospace, 12f);
In place of merging, one can also replace existing MdiParent menus with Child menus.
Activity: Add an Edit to the ChildForm class
MergeAction's property to replaceA quick way to provide functionality to edit menu items is to use the TextBox methods (inherited from TextBoxBase)
richTextBox1.Undo(); richTextBox1.Cut(); richTextBox1.Copy(); richTextBox1.Paste(); richTextBox1.SelectAll();
URL: http://www/cwu.edu /~gellenbe/446/labs/lab7.php
Author: Ed Gellenbeck, Department of Computer Science, Central Washington University, gellenbe@cwu.edu
Copyright 2006 Ed Gellenbeck, Central Washington University
Last modified: March 22, 2008