-->

Monday, June 24, 2013

How to create MDI container form and open child forms in it

How to create MDI container form and open child forms in it



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

MDI form

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.

MDI 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.

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved