A multi-Document Interface Application

Source: Internet
Author: User

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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.