1创建窗体
2并在属性IsMdiContainer设置为true
3最好将父窗体设置最大化WindowState设置为Maximized
4设置显示活动子窗体,在menuStrip属性设置MdiWindowListItem,设置子菜单项
5设置下方代码
代码贴出:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 窗口ToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (Form childrenForm in this.MdiChildren)
{
//检测是不是当前子窗体名称
if (childrenForm.Name == "Form2")
{
//是的话就是把他显示
childrenForm.Visible = true;
//并激活该窗体
childrenForm.Activate();
return;
}
}
Form2 newMDIChild = new Form2();
// Set the parent form of the child window.
newMDIChild.MdiParent = this;
newMDIChild.WindowState = FormWindowState.Maximized;
// Display the new form.
newMDIChild.Show();
}
}