Namespace Microsoft. Samples. WinForms. Cs. MDI {
Using System;
Using System. ComponentModel;
Using System. Drawing;
Using System. WinForms;
Public class MainForm: System. WinForms. Form {
Private System. ComponentModel. Container components;
Private System. WinForms. MainMenu mainMenu;
Private System. WinForms. StatusBar statusBar1;
Private int windowCount = 0;
Public MainForm (){
// Required by the Windows Forms Designer
InitializeComponent ();
// TODO: Add any constructor code after InitializeComponent call
// Setup MDI stuff
This. IsMDIContainer = true;
This. MDIChildActivate + = new EventHandler (this. MDIChildActivated );
// Add File Menu
MenuItem miFile = mainMenu. MenuItems. Add ("& File ");
MiFile. MergeOrder = 0;
MiFile. MergeType = MenuMerge. MergeItems;
MenuItem miAddDoc = new MenuItem ("& Add Document", new EventHandler (this. FileAdd_Clicked), Shortcut. CtrlA );
MiAddDoc. MergeOrder = 100;
MenuItem miExit = new MenuItem ("E & xit", new EventHandler (this. FileExit_Clicked), Shortcut. CtrlX );
MiExit. mergeorge = 110;
MiFile. MenuItems. Add (miAddDoc );
MiFile. MenuItems. Add ("-"); // Gives us a seperator
MiFile. MenuItems. Add (miExit );
// Add Window Menu
MenuItem miWindow = mainMenu. MenuItems. Add ("& Window ");
MiWindow. MergeOrder = 10;
MiWindow. MenuItems. Add ("& Cascade", new EventHandler (this. WindowCascade_Clicked ));
MiWindow. MenuItems. Add ("Tile & Horizontal", new EventHandler (this. WindowTileH_Clicked ));
MiWindow. MenuItems. Add ("Tile & Vertical", new EventHandler (this. WindowTileV_Clicked ));
MiWindow. MDIList = true; // Adds the MDI Window List to the bottom of the menu
AddDocument (); // Add an initial doc
}
// Add a document
Private void AddDocument (){
WindowCount ++;
Document doc = new Document ("Document" + windowCount );
Doc. MDIParent = this;
Doc. Show ();
}
// File-> Add Menu item handler
Protected void FileAdd_Clicked (object sender, System. EventArgs e ){
AddDocument ();
}
// File-> Exit Menu item handler
Protected void FileExit_Clicked (object sender, System. EventArgs e ){
This. Close ();
}
// One of the MDI Child windows has been activated
Protected void MDIChildActivated (object sender, System. EventArgs e ){
If (null = this. ActiveMDIChild ){
StatusBar1.Text = "";
} Else {
StatusBar1.Text = this. ActiveMDIChild. Text;
}
}
// Window-> Cascade Menu item handler
Protected void WindowCascade_Clicked (object sender, System. EventArgs e ){
This. LayoutMDI (MDILayout. Cascade );
}
// Window-> Tile Horizontally Menu item handler
Protected void WindowTileH_Clicked (object sender, System. EventArgs e ){
This. LayoutMDI (MDILayout. TileHorizontal );
}
// Window-> Tile Vertically Menu item handler
Protected void WindowTileV_Clicked (object sender, System. EventArgs e ){
This. LayoutMDI (MDILayout. TileVertical );
}
Public override void Dispose (){
Base. Dispose ();
Components. Dispose ();
}
Protected void InitializeComponent (){
This. components = new System. ComponentModel. Container ();
This. mainMenu = new System. WinForms. MainMenu ();
This. statusBar1 = new System. WinForms. StatusBar ();
This. AutoScaleBaseSize = new System. Drawing. Size (5, 13 );
This. Text = "MDI Example ";
This. Menu = mainMenu;
This. ClientSize = new System. Drawing. Size (450,200 );
StatusBar1.BackColor = System. Drawing. SystemColors. Control;
StatusBar1.Size = new System. Drawing. Size (496, 20 );
StatusBar1.TabIndex = 1;
StatusBar1.Text = "";
StatusBar1.Location = new System. Fig. Point (0,273 );
This. Controls. Add (statusBar1 );
}
Public static void Main (string [] args ){
Application. Run (new MainForm ());
}
}
}
Author: jspfuns