To make a Form MDI Form
Making a Form MDI Parent
MDI stands for Multiple Document Interface. By making a form MDI parent we can open multiple forms within that form.
How to make a form MDI Form:
· Start a new WindowsFormApplication
· A form will appear.
· Select the Form and go to the Properties Window.
· In properties window set name property as MainForm.
· Now go to Project tab.
· Select Add Windows Form.
· Name it as ChildForm.
· A new Form will be added.
· Now select the MainForm and go to Properties Window.
· In properties window set the property IsMdiContainer to true as shown below.
· Also set the property WindowState to maximized.
· Add a MenuStrip to the Form from toolbox and add one menu item ShowChildForm to New menu tab.
· Add the code behind ShowChildForm click event.
Now to open ChildForm in its parent form add following code in MainFormClass
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Data
{
public partial class MainForm : Form
{
internal ChildForm chfm;
public MainForm()
{
InitializeComponent();
}
private void ShowChildFormToolStripMenuItem_Click(object sender, EventArgs e)
{
if (chfm == null)
{
chfm = new ChildForm();
chfm.MdiParent = this;
chfm.Show();
}
chfm.BringToFront();
chfm = null;
}
}
}
Now run the application.
Now when you will click the ShowChildForm menu item the ChildForm will open in MainForm like this.
Comments
Post a Comment