MDI Forms in C#


Description :

The following source code will provide the use of MDI Forms in C#.



Source Code:

using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
class MDIDemo:Form
{
private static int FormCount=0;
MainMenu mnuMain=
new MainMenu();
MenuItem FileMenu;
MenuItem NewMenu;
MenuItem ExitMenu;
MenuItem WindowMenu;
public MDIDemo()
{
this.IsMdiContainer=true;
this.Text="MDI Demo";
FileMenu=
new MenuItem();
FileMenu.Text="&File";
WindowMenu=
new MenuItem();
WindowMenu.Text="&Window";
WindowMenu.MenuItems.Add("&Cascade",
new EventHandler(Cascade_Click));
WindowMenu.MenuItems.Add("Tile &Horizontally",new EventHandler(TileH_Click));
WindowMenu.MenuItems.Add("Tile &Vertically",
new EventHandler(TileV_Click));
WindowMenu.MdiList=
true;
NewMenu=
new MenuItem();
NewMenu.Text="&New";
NewMenu.Click+=
new EventHandler(New_Click);
ExitMenu=
new MenuItem();
ExitMenu.Text="E&xit";
ExitMenu.Click+=
new EventHandler(Exit_Click);
FileMenu.MenuItems.Add(NewMenu);
FileMenu.MenuItems.Add(
new MenuItem("-"));
FileMenu.MenuItems.Add(ExitMenu);
mnuMain.MenuItems.Add(FileMenu);
mnuMain.MenuItems.Add(WindowMenu);
this.Menu=mnuMain;
}
private void Cascade_Click(object sender,EventArgs e)
{
this.LayoutMdi(MdiLayout.Cascade);
}
private void TileH_Click(object sender,EventArgs e)
{
this.LayoutMdi(MdiLayout.TileHorizontal);
}
private void TileV_Click(object sender,EventArgs e)
{
this.LayoutMdi(MdiLayout.TileVertical);
}
private void New_Click(object sender,EventArgs e)
{
Form frmTemp=
new Form();
frmTemp.MdiParent=
this;
frmTemp.Text="Window#" + FormCount.ToString();
FormCount++;
frmTemp.Show();
}
private void Exit_Click(object sender,EventArgs e)
{
this.Dispose();
Application.Exit();
}
public static void Main()
{
Application.Run(
new MDIDemo());
}
}


Similar Articles