1024programmer Asp.Net [C#][WinForm]MDI form

[C#][WinForm]MDI form

【C#】【WinForm】MDI Form

Related learning and use of MDI forms

1. Set the MDI parent form

Find the IsMdiContainer option in the properties and set it to True

2. To add an MDI subform, select Add -> Form in the project, and then leave it as default

The added project directory (Form1 is the parent window, Form2 and Form3 are child windows)

3. In Form1.cs, create an object corresponding to the MDI sub-window and call it to display

 1 namespace WindowsFormsApp1
  2 {
  3 public  span> partial class   Form1 : Form
  4  {
  5 public  span> Form1()
  6  {
  7  InitializeComponent()  ;
  8  }
  9
 10 private void Form1_Load(object sender, EventArgs e)
 11  {
 12 Form form2 =   new Form2();
 13  form2.Show  ();
 14 form2.MdiParent = this;
 15 Form form3 =   new Form3();
 16  form3.Show  ();
 17 form3.MdiParent = this;
 18  }
 19  }
 20 }

After saving and running, all sub-windows will be displayed.

4. Arrange and display sub-windows in a specific way

Required controls (Menu and Toolbar -> Menu Strip)

Add Items in sequence in the design interface

Double-click each Item in order, and then add the following code to the Form1.cs file:

 private void Arrange ToolStripMenuItem_Click(object sender,  EventArgs e)
         {
             LayoutMdi(MdiLayout.TileHorizontal);
         }

         private void  span> vertically arrange ToolStripMenuItem_Click(object sender  , EventArgs e)
         {
             LayoutMdi(MdiLayout.TileVertical);
         }

         private void Stacked arrangement ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             LayoutMdi(MdiLayout.Cascade);
         }

Complete Form1.cs code:

 1 using System;
  2 using  span> System.Collections.Generic;
  3 using  span> System.ComponentModel;
  4 using  span> System.Data;
  5 using  span> System.Drawing;
  6 using  span> System.Linq;
  7 using  span> System.Text;
  8 using  span> System.Threading.Tasks;
  9 using  span> System.Windows.Forms;
 10
 11 namespace WindowsFormsApp1
 12 {
 13 public  span> partial class   Form1 : Form
 14  {
 15 public  span> Form1()
 16  {
 17  InitializeComponent()  ;
 18  }
 19
 20 private void Form1_Load(object sender, EventArgs e)
 21  {
 22 Form form2 =   new Form2();
 23  form2.Show  ();
 24 form2.MdiParent = this;
 25 Form form3 =   new Form3();
 26  form3.Show  ();
 27 form3.MdiParent = this;
 28  }
 29
 30 private void Arrange ToolStripMenuItem_Click(object horizontally   sender, EventArgs e)
 31  {
 32  LayoutMdi(MdiLayout  .TileHorizontal);
 33  }
 34
 35 private void vertically arrange ToolStripMenuItem_Click(object   sender, EventArgs e)
 36  {
 37  LayoutMdi(MdiLayout  .TileVertical);
 38  }
 39
 40 private void Stacked arrangement ToolStripMenuItem_Click(object   sender, EventArgs e)
 41  {
 42  LayoutMdi(MdiLayout  .Cascade);
 43  }
 44  }
 45 }

About Form.cs Form1.Designer.cs Form1.cs[Design] The functions of these three files:

Form1.cs [Design] is a front-end interface designer, which is the same as the Designer in QT. It uses a graphical interface to design the display effect of the application and simplify the front-end workload.

Form1.Designer.cs is a synchronously generated front-end code storage file after setting the interface through the designer. It is mainly used to define the layout of the form, the position and properties of the controls, etc.

Form.cs is used for back-end business processing to implement complex logic and functions, including the code logic of the form class, such as control initialization, event processing, etc.

ba(0, 0, 0, 1)”> {
32 LayoutMdi(MdiLayout .TileHorizontal);
33 }
34
35 private void vertically arrange ToolStripMenuItem_Click(object sender, EventArgs e)
36 {
37 LayoutMdi(MdiLayout .TileVertical);
38 }
39
40 private void Stacked arrangement ToolStripMenuItem_Click(object sender, EventArgs e)
41 {
42 LayoutMdi(MdiLayout .Cascade);
43 }
44 }
45 }

About Form.cs Form1.Designer.cs Form1.cs[Design] The functions of these three files:

Form1.cs [Design] is a front-end interface designer, which is the same as the Designer in QT. It uses a graphical interface to design the display effect of the application and simplify the front-end workload.

Form1.Designer.cs is a synchronously generated front-end code storage file after setting the interface through the designer. It is mainly used to define the layout of the form, the position and properties of the controls, etc.

Form.cs is used for back-end business processing to implement complex logic and functions, including the code logic of the form class, such as control initialization, event processing, etc.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/cwinformmdi-form-2/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索