MDI, stands for Multiple
Document Interface, is a user interface that enable user to work with more than
one document at the same time. Each document is displayed in a separate window
called child window. A child window cannot appear outside the main window
because it is confined in main window.
To create MDI parent form:
- Add a new form "MainForm"
- In properties window set IsMdiContainer property to true
- Drag a Menustrip from the toolbox and create some menus like New, Open and Save etc. This menu bar can be used by all child windows because it is in parent window
Run the project and see the form something like
below form
To create MDI child form:
- Add new form in the project i.e. Form2
- In the click event of “New” menu item write
following code to open a child window
Form2 childForm = new Form2();
childForm.MdiParent = this;
childForm.Show();
Run the project and when we click on new menu
item a child window will open
To get title of Active MDI child window
- Add a new menu item “Get Active Form”
- In the click event of this menu item write
following code
Form activeForm = this.ActiveMdiChild as Form;
string title = activeForm.text;
MessageBox.Show(title);
Run the project and open some child forms. Click
on “Get Active Form” menu button and a message box will appear having title of
currently active child form.
So this is how we make MDI container form with a child form. We can open more child form using the same method.