Use Multiple Document Interface (MDI) In Windows Form Using C#

In this tutorial I’ll show you how to use Multiple Document Interface (MDI) in windows from using C#.

INITIAL CHAMBER

Step 1

Open Visual Studio 2010 and go to File, New, Projects, then under Visual C# select Windows.



You can change the name of the project and browse your project to different location too and then press OK.

DESIGN CHAMBER

Step 2

Now open your Form1.cs [Design] file, where we create our design for MDI. We will drag two buttons to start our MDI in Form1.cs [Design]. You can see the following screen:.



In Form1.cs design, you have to change the width of the form as it will open another form, so your form will not be visible.. Therefore change its width. There is one more property - IsMdiContainer, make it True.

 
Again go back to your Project - Add New Item and select Form2.cs. In the same way again add new form - - Form3.cs.

CODE CHAMBER

Right click on the blank part of Form1.cs  and View Code. You will see you are entered in the code part of the form. Write the following code and then Press F5 to run the project.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9.   
  10. namespace WindowsFormsApplication4  
  11. {  
  12.     public partial class Form1 : Form  
  13.     {  
  14.         public Form1()  
  15.         {  
  16.             InitializeComponent();  
  17.         }  
  18.   
  19.         Form2 frm2;  
  20.   
  21.         private void button2_Click(object sender, EventArgs e)  
  22.         {  
  23.             
  24.             if (frm2==null)  
  25.             {  
  26.                   
  27.                 frm2 = new Form2();  
  28.                 frm2.MdiParent = this;  
  29.                 frm2.Show();  
  30.                 
  31.             }  
  32.             else  
  33.             {  
  34.                 frm2.Activate();  
  35.             }  
  36.         }  
  37.   
  38.         private void button3_Click(object sender, EventArgs e)  
  39.         {  
  40.               
  41.             for (int i = 0; i < 50; i++)  
  42.             {  
  43.                 Form3 frm3 = new Form3();  
  44.                 frm3.MdiParent = this;  
  45.                 frm3.Show();  
  46.                   
  47.             }  
  48.         }  
  49.     }  
  50. }  
OUTPUT CHAMBER



Open Form 2



Open Form 3


 
You can use MDI for Tool Menu Strip for getting the benefits. Hope you liked this. Have a good day. Thank you for reading.

Up Next
    Ebook Download
    View all
    Learn
    View all