MDI Form

Applications using a Multi-Document-Interface (MDI) allow multiple documents to be displayed simultaneously in their own window, with each document. The Window menu items of MDI applications often have submenus for switching between windows or documents.

If we set the IsMdiContainer property to True, any windows can become an MDI parent.

IsMdiContainer = true;

Step1: In Visual Studio create a project for the Windows Application.

Step2: Select a form which we want to parent form then,Set the IsMdiContainer property to true in the Properties window. and its WindowsState property to Maximized.

Step3: Pull the MenuStrip control in the form from the Toolbox. Set your Text to File property.

Step4: To add two child strip menu items click the ellipses (...) next to the items property, and click Add. Set the New and Window text property for those items.

Step5: Right-click the project in Solution Explorer, point to Add, then select Add New Item.

Step6: From the Templates pane, select Windows Form (in Visual C #) or Windows Forms (.NET) (in Visual C++) in the Add New Item dialog box. Click the Open button in the Name Box to add the form to the project. Name Form2 form. This form is our MDI child form template.

Step7: Pull a RichTextBox check into the form from the toolbox.

Step8: Set the Anchor property to Top, Left and Dock property to Fill in the Properties window. This causes the RichTextBox control, even when the form is redimensional, to completely fill the MDI child form area.

Step9: To create Click Event Handler for it, double-click the New Menu item.

Step10: Please add code like the following when clicking the New menu item to create a new MDI child form.

Step11: Select the menu strip corresponding to the menu strip and set MdWindowListItem to Window ToolStripMenuItem in the drop down list at the top of the Properties window.

Step12: The window menu will allow the list of MDI child windows to be maintained with a check mark next to the children window.

Step13: Click on F5 to start the application. You can create new MDI child forms that are tracked on the Window menu item by selecting the New from the File menu.

Note: Please note, that each MDI child form will raise a Closing Event before the MDI parent Closing Event will be raised.

Canceling the closing of a MDI child's event does not prevent the closing of the MDI parent's event; The argument CancelEventArgs will now be set to true for the MDI parent Closing event.

By setting the CancelEventArgs argument to false, we can force the parent and all MDI child forms to close.

protected void MDIChildNew_Click(object sender, System.EventArgs e){
   Form2 newMDIChild = new Form2();
   // Set the Parent Form of the Child window.
   newMDIChild.MdiParent = this;
   // Display the new form.

MDI Form C#

MDI Form Source Code


Video Tutorial