父窗体里设置
IsMdiContainer=true; //确定窗体是否是MDI容器(在属性里)
frmsp.MdiParent = this;// frmsp子窗体 this父窗体
子窗体里设置(放在Load方法中即可)
this.ControlBox = false;
// 设置不出现关闭最大化最小化按钮(尽量放在第一行,放在后面可能不起作用)
this.WindowState = FormWindowState.Maximized;
// 获取或设置窗体的窗口状态
父窗体代码
Form4 f4;
private void TSMI_Serial_Click(object sender, EventArgs e)
{
try
{
ToolStripMenuItem tsmi = (ToolStripMenuItem)sender;
switch (tsmi.Name)
{
case "TSMI_a":
if (f4 == null || f4.IsDisposed == true)//表示子窗体没有实例化
{
f4 = new Form4();
f4.MdiParent = this;
f4.Show();
}
else
{
f4.MdiParent = this;
f4.Show();
}
break;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}