首先创建一个判断函数,判断窗体是否已经打开:
public bool openonece(Form myform)
{
foreach (Form frm in this.MdiChildren)
{
if (frm.Name == myform.Name)
{
frm.Activate();
frm.WindowState = FormWindowState.Maximized;
return true;
}
}
return false;
}
然后点击MDI窗体中的菜单按钮时编写代码:
private void tool_Print_Label_Click(object sender, EventArgs e)
{
Form frm = new Form_Name();//Form_Name为要打开窗体的NAME属性中的名称
if (openonece(frm) == false)
{
frm.MdiParent = this;
frm.WindowState = FormWindowState.Maximized;//最大化窗体
frm.Show();
}
}