Multiple Document Interface (MDI) Applications


In this piece of writing I explain regardingMultiple Document Interface (MDI) applications. (MDI) applications letyou to show multiple documents at the same time, with every documentdisplayed in its individual window.

CREATING MDI PARENT FORMS:

The base of a Multiple Document Interface(MDI) is the MDI parent form. This is the form that holds the MDI childwindows, which are all the "sub-windows" in which the client worktogether with the MDI application.

To create an MDI parent form:

Create a new form and add the codethis.IsMDIContainer = true;This assign the form as an MDI container for child windows.

CREATING MDI CHILD FORMS:

An vital constituent of Multiple DocumentInterface (MDI) Applications is the MDI child forms, as these are themain windows for client interaction.

To create MDI child forms

Form frmchild=new Form();
frmchild.MDIParent=this;
frmchild.Show();

Determining the Active MDI Child

In a number of circumstance, we desire to givea command that operates on the control with the focus on the at presentactive child form.
For the reason that an application can have many instances of the samechild form, the process wants to be acquainted with which form to use.To specify this, use the ActiveForm property of an MDI Form, whichreturns the child form that has the focus.
In any case one MDI child form must be loaded and visible when you access the ActiveForm property, or an error is returned.

ARRANGING CHILD FORMS:

Frequently, applications will have menucommands for actions such as Tile, Cascade, and Arrange, withconcerning to the open MDI child forms. One can use the LayoutMDImethod with the MDILayout enumeration to rearrange the child forms inan MDI parent form.

The MDILayout enumeration can be set to fourdifferent values, which will display child forms as cascading, ashorizontally or vertically. Often, these methods are used as the eventhandlers called by a menu item's Click event. In this way, a menu itemwith the text "Cascade Windows" can have the desired effect on the MDIchild windows.

In the example below, the event handler for the Click event for the Cascade menu item sets the MDILayout enumeration to Cascade for the child windows of the MDI Parent form.

The Example:

using System;
using System.ComponentModel;
using System.WinForms;
using System.Drawing;

public class MDI :Form {
private MainMenu mainMenu;
private int Count=0;
public MDI() {
this.IsMDIContainer=true;
this.Text="MDI Demo";
mainMenu = new MainMenu();
MenuItem File = mainMenu.MenuItems.Add("&File");

File.MenuItems.Add(new MenuItem("&New",new EventHandler(this.FileNew_clicked),Shortcut.CtrlN));

File.MenuItems.Add(new MenuItem("&Active Child",new EventHandler(this.FindActive_clicked),Shortcut.CtrlA));

File.MenuItems.Add(new MenuItem("-"));

File.MenuItems.Add(new MenuItem("&Exit",new EventHandler(this.FileExit_clicked),Shortcut.CtrlX));

MenuItem Arrange = mainMenu.MenuItems.Add("&Arrange");
Arrange.MenuItems.Add(new MenuItem("&Cascade",new EventHandler(this.Cascade_clicked),Shortcut.F1));
Arrange.MenuItems.Add(new MenuItem("&Horizontal",new EventHandler(this.Horizontal_clicked),Shortcut.F2));
Arrange.MenuItems.Add(new MenuItem("&Vertical",new EventHandler(this.Vertical_clicked),Shortcut.F3));

this.Menu=mainMenu;
mainMenu.GetForm().BackColor = Color.Indigo ;

}
private void FileExit_clicked(object sender, EventArgs e) {
this.Close();
}
private void FindActive_clicked(object sender, EventArgs e) {
MessageBox.Show(this.ActiveMDIChild.Text,"MDI FORM",MessageBox.IconInformation);
}
private void FileNew_clicked(object sender, EventArgs e) {

Form frmchild=new Form();
frmchild.MDIParent=this;
frmchild.Show();
frmchild.Text="Child Form" + Count.ToString();
Count++;
}

private void pop_Clicked(object sender, EventArgs e) {

MessageBox.Show("Popupmenu","MENU_CREATION",MessageBox.IconInformation);
}
private void Cascade_clicked(object sender, EventArgs e) {

this.LayoutMDI(MDILayout.Cascade );

}

private void Horizontal_clicked(object sender, EventArgs e) {

this.LayoutMDI(MDILayout.TileHorizontal);

}
private void Vertical_clicked(object sender, EventArgs e) {

this.LayoutMDI(MDILayout.TileVertical);

}
public static void Main(string[] args) {
Application.Run(new MDI());
}
}

The Output:

pic1 Multiple Document Interface (MDI) Applications

pic2 Multiple Document Interface (MDI) Applications

About the Author:

G.GNANA ARUN GANESH is Admin and the founderof www.onlinecsharpteach.netfirms.com. He has been programming in C,C++, Visual Basic, COM for 3 years. Arun's background includes Bachelordegree in ECE. He is an Active person in the panel of TechnicalReviewers in Prentice Hall Publishers and Sams Publishers. He is alsowriting articles particularly in C# in various websites. For moreinformation visit www.geocities.com/arunganeshgg/index.html.

Most Commented Articles :

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!