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.
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
-
- namespace WindowsFormsApplication4
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- Form2 frm2;
-
- private void button2_Click(object sender, EventArgs e)
- {
-
- if (frm2==null)
- {
-
- frm2 = new Form2();
- frm2.MdiParent = this;
- frm2.Show();
-
- }
- else
- {
- frm2.Activate();
- }
- }
-
- private void button3_Click(object sender, EventArgs e)
- {
-
- for (int i = 0; i < 50; i++)
- {
- Form3 frm3 = new Form3();
- frm3.MdiParent = this;
- frm3.Show();
-
- }
- }
- }
- }
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.