1、设置父窗体:
如果要将某个窗体设置为父窗体,只需将该窗体的IsMdiContainer属性设置为True即可。
2、设置子窗体:
通过设为某个窗体的MdiParent属性来确定该窗体是那个窗体的子窗体。
语法如下:
public Form MdiParent{get;set;}
3、排列MDI子窗体:
语法如下:
public void LayoutMdi(MdiLayout value)
value:是MdiLayout的枚举值之一,用来定义MDI子窗体的布局。
枚举成员 | 说明 |
Cascade | 层叠排列MDI子窗体 |
TileHorizontal | 水平平铺MDI子窗体 |
TileVertical | 垂直平铺MDI子窗体 |
例程;
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
private void 加载子窗体ToolStripMenuItem_Click(object sender, EventArgs e)
{
FormChild_1 frm1 = new FormChild_1();
frm1.MdiParent = this;
frm1.Show();
FormChild_2 frm2 = new FormChild_2();
frm2.MdiParent = this;
frm2.Show();
FormChild_3 frm3 = new FormChild_3();
frm3.MdiParent = this;
frm3.Show();
}
private void 水平平铺ToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileHorizontal);
}
private void 垂直平铺ToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileVertical);
}
private void 层叠排列ToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.Cascade);
}
}