Click here to Skip to main content
13,094,001 members (51,529 online)
Click here to Skip to main content
Add your own
alternative version


21 bookmarked
Posted 6 Mar 2006

Adding MDI Support to Windows Forms Applications (.NET)

, 6 Mar 2006
Rate this:
Please Sign up or sign in to vote.
An article on adding MDI support to .NET applications.

Final Application


This article will demonstrate an easy and effective way to include MDI support in your Windows Forms Applications (.NET)! There are many examples on MSDN, but none of them puts together a sample program that is all in one place. Adding MDI support to your application gives you the advantage of managing multiple files or some other form of data with one template. This will dramatically reduce the amount of coding that you have to do, and will allow end users the comfort of working with an application that gives them the power to work with tons of data all at once. This article will show you how to setup a basic application with MDI support that uses a RichEdit control to provide a text editor.

Using the code

In the source zip, you will find this entire project with all the steps completed below.

First of all, this article is written mainly for Microsoft Visual C++ .NET 2003 users. There is no guarantee that this code will work with previous or future versions! Let's start off by opening a blank Microsoft Forms Application (.NET) and naming it MDIApp.

Step 1

Click OK, and you will be presented with a blank form named Form1. Because it will require you to modify many lines and filenames, I will not go through changing this name, but if you decide to change Form1 to something different, you must substitute Form1 for whatever you decided to name it for the rest of this article.

Next, click the form and open the Properties window. Under ismdicontainer change the value to true. This will tell the compiler that we want this to be our MDI parent. If you wish, you can change other values to make the form appear like you want. I recommend changing WindowState to Maximize to produce a full screen window.

Step 2

Now that we have our MDI container, we need to add a menu. Drag a MainMenu control from the toolbar onto your form. Create a top-level menu item with the Text property set to &File, with submenu items called &New and E&xit. Also create a top-level menu item called &Window. Select the menu item that corresponds to the &Window menu item, and set the MdiList property to true. This will tell our application that we want it to append child windows at the end as a submenu under the &Window menu.

Now that we have our parent window, it's time to create a child window. In the Solution Explorer, right-click the project, point to Add, and then select Add New Item. In the Add New Item dialog box, select Windows Forms Application (.NET) from the Templates pane. In the Name box, name the form Form2 (again, if you change this, you will have to substitute). Click the Open button to add the form to the project. Form2 will open by default. This form will be the template for your MDI child forms. Even though you will have the option of changing the Opacity property on your child window, do not do it! This will cause painting problems to occur.

Drag a RichTextBox control from the Toolbox to the form. In the Properties window, set the Anchor property to Top, Left and the Dock property to Fill. This will make our RichTextBox fill up the entire child window! Create a Click event handler for the New menu item. This is best done by double clicking the New sub-item on the menu (in design mode).

Add the following code under our new function that was created:

<PRE lang=mc++>private: System::Void menuItem2_Click(System::Object * sender, System::EventArgs * e) { // This gets a new instance of our child window. Form2* newMDIChild = new Form2(); // Tells our new child window // what is our parent window. newMDIChild->MdiParent = this; // Shows the new form. // Don't confuse this with ShowDialog! newMDIChild->Show(); }

That will create a new child window with the design that we made. Scroll to the top and add the line below...

<PRE lang=mc++>#include "Form2.h"

Go back to our design view and create a click event handler for the Exit menu item.

Add the following code under our new function that was created for the Exit menu item:

<PRE lang=mc++>private: System::Void menuItem3_Click(System::Object * sender, System::EventArgs * e) { this->Close(); // Closes the application! }

Press F5 to run the application. Note that by selecting New from the File menu, you can create new MDI child forms, which are kept track of in the Window menu.

Points of Interest

Before I learned about MDI for .NET, I was forced to use Microsoft's alternative method in making my program MFC. This wasn't useful for me because I am new to MFC and don't know many functions. Also, it is useful to add XP support so that people with XP will see a cleaner design. It will also help to add a status bar to fill the missing space at the bottom of the window. The last thing is something in my preference but it is recommended that you set your child window to Maximize for WindowState for better appearance.


So far this is the first article and first version of this article that I have made! ;-)


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Gabriel Graves
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralTitle change Pin
R. Senthil Kumaran18-Oct-08 21:32
memberR. Senthil Kumaran18-Oct-08 21:32 
GeneralRe: Title change Pin
Gabriel Graves18-Oct-08 21:35
memberGabriel Graves18-Oct-08 21:35 
GeneralProblem Pin
C# Beginner Nick25-Aug-08 16:54
memberC# Beginner Nick25-Aug-08 16:54 
GeneralVisual 2005 Express Edition Pin
SzyKam17-Aug-06 21:05
memberSzyKam17-Aug-06 21:05 
GeneralRe: Visual 2005 Express Edition Pin
Gabriel Graves18-Aug-06 17:34
memberGabriel Graves18-Aug-06 17:34 
QuestionExtention? Pin
Dr. Pastor10-Apr-06 10:14
memberDr. Pastor10-Apr-06 10:14 
AnswerRe: Extention? Pin
Gabriel Graves10-Apr-06 11:07
memberGabriel Graves10-Apr-06 11:07 
GeneralRe: Extention? Pin
Dr. Pastor11-Apr-06 6:44
memberDr. Pastor11-Apr-06 6:44 
AnswerRe: Extention? Pin
Gabriel Graves11-Apr-06 12:59
memberGabriel Graves11-Apr-06 12:59 
GeneralRe: Extention? Pin
kaiwalle30-May-06 7:13
memberkaiwalle30-May-06 7:13 
GeneralRe: Extention? Pin
Dr. Pastor30-May-06 11:17
memberDr. Pastor30-May-06 11:17 
QuestionIn VB.NET? Pin
Sheshadrinath14-Mar-06 17:29
memberSheshadrinath14-Mar-06 17:29 
AnswerRe: In VB.NET? Pin
Gabriel Graves15-Mar-06 11:10
memberGabriel Graves15-Mar-06 11:10 
General"D" in MDI... Pin
Jun Du6-Mar-06 12:20
memberJun Du6-Mar-06 12:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 6 Mar 2006
Article Copyright 2006 by Gabriel Graves
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid