Windows Forms: How to use Multiple Document Interface (MDI) in C#

How to Create a MDI Form in C#. MDI child forms are an essential element of Multiple-Document Interface Applications, as these forms are the center of user interaction.

Step 1Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "MdiForm" and then click OK

c# mdi formStep 2: Design your form as below

mdi form in c#

From the Toolbox, drag a MenuStrip control to the form, then add items to your menu

You need to create an empty Form2 to play demo, as same as Form3, Form4, Form5

Step 3: Add code to handle your form as below

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MdiForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //Show MDI form
        private void ShowForm(Form frm)
        {
            frm.MdiParent = this;
            frm.Show();
            frm.Activate();
        }

        private void form1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowForm(Form2.Instance);
        }

        private void form2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowForm(Form3.Instance);
        }

        private void form3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form4 frm = new Form4();
            frm.MdiParent = this;
            frm.Show();
        }

        private void form4ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form5 frm = new Form5();
            frm.MdiParent = this;
            frm.Show();
        }
    }
}

VIDEO TUTORIALS