In this Application we have to show the working of MDI Form and their various Properties with the help of an example. Choose a New Project and Name as MDISample, Next Right Click on the right hand side of MDISample and Click on ADD Option then Click on ADD item, then chooses an Option MDIParent Form as shown below as shown in arrow.
As we click on MDIParent form you will see Below or we can use menus as well as ToolStrip task with the help of control as shown Below with the help of an Arrow.
As in the above figure we can see all the functionalities as normal notepad as vertical tiles, Horizontal Tiles, cascade, close all, Arrange Icons etc.
The Code Snippet as shown below
publicpartialclassMDIParent1 : Form
{
privateint childFormNumber = 0;//Initializing childformno as 0.
public MDIParent1()
{
InitializeComponent();
}
privatevoid ShowNewForm(object sender, EventArgs e)
{
Form childForm = newForm();//Creating Object of Form
childForm.MdiParent = this;
childForm.Text = "Window " + childFormNumber++;
childForm.Show();
}
privatevoid OpenFile(object sender, EventArgs e)
{
//Creating an object of openFileDialog and checking the open file into the same form.
OpenFileDialog openFileDialog = newOpenFileDialog();
//openning the file as initial directory
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
string FileName = openFileDialog.FileName;
}
}
privatevoid SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
{ //Creating an object of savefile dialog
SaveFileDialog saveFileDialog = newSaveFileDialog();
//saving the file in a initial directory
saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
//Checking condition for save Dialog box
if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
{
string FileName = saveFileDialog.FileName;
}
}
privatevoid ExitToolsStripMenuItem_Click(object sender, EventArgs e)
{ //Closing the application
this.Close();
}
privatevoid CutToolStripMenuItem_Click(object sender, EventArgs e)
{
}
privatevoid CopyToolStripMenuItem_Click(object sender, EventArgs e)
{
}
privatevoid PasteToolStripMenuItem_Click(object sender, EventArgs e)
{
}
privatevoid ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
{
toolStrip.Visible = toolBarToolStripMenuItem.Checked;
}
privatevoid StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
{
statusStrip.Visible = statusBarToolStripMenuItem.Checked;
}
privatevoid CascadeToolStripMenuItem_Click(object sender,EventArgs e)
{//for cascading
LayoutMdi(MdiLayout.Cascade);
}
privatevoid TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
{//for Tile verticle
LayoutMdi(MdiLayout.TileVertical);
}
privatevoid TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
{//For Horizontal
LayoutMdi(MdiLayout.TileHorizontal);
}
privatevoid ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
{//for Arrange icons
LayoutMdi(MdiLayout.ArrangeIcons);
}
privatevoid CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (Form childForm in MdiChildren)
{//closing Form
childForm.Close();
}
}
Anonymous User
12-Mar-2019Thank You for the information.
Samuel Fernandes
13-Jul-2017I always seek to read your articles.