Windows Forms: How to use Multiple Document Interface (MDI) in C#
By FoxLearn 7/28/2017 9:56:35 PM 6.78K
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 1: Click 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
Step 2: Design your form as below
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
- Windows Forms: Advanced Filter DataGridView in C#
- Windows Forms: Progress Bar in C#
- How to create a Lucky Draw games in C#
- Windows Forms: Youtube Search with Paging in C#
- Windows Forms: How to Create a Random Password Generator in C#
- Windows Forms: Tag Control in C#
- Windows Forms: Wait Form Dialog in C#
- Windows Forms: Text to speech in C#
Categories
Popular Posts
Visual Studio: Auto increment version
03/22/2024
What is ARM architecture?
03/11/2024