1、首先确定一个父窗体,将IsMdiContaine设置为true。
2、创建子窗体,并且设置他们的父窗体。
MenuStrip:显示按钮功能的分组的应用程序命令和选项。
Form.MdiParent:获取或设置此窗体的当前多文档界面(MDI)父窗体。
显示子窗体,横纵向排列:
public partial class FatherForm : System.Windows.Forms.Form
{
public FatherForm()
{
InitializeComponent();
}
private void 显示子窗体ToolStripMenuItem_Click(object sender, EventArgs e)
{
//显示子窗体
//使Form2的父窗体为Form1
SubFormOne sub1 = new SubFormOne();
sub1.MdiParent = this;
sub1.Show();
//使Form3的父窗体为Form1
SubFormTwo sub2 = new SubFormTwo();
sub2.MdiParent = this;
sub2.Show();
//使Form4的父窗体为Form1
SubFormThree sub3 = new SubFormThree();
sub3.MdiParent = this;
sub3.Show();
}
/// <summary>
/// 将所有子窗体横向排列
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 横向排列ToolStripMenuItem_Click(object sender, EventArgs e)
{
//LayoutMdi方法,Mdilayout枚举类型
LayoutMdi(MdiLayout.TileHorizontal);
}
/// <summary>
/// 将所有子窗体纵向排列
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 纵向排列ToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileVertical);
}
}