public static void openChildrenWindow(System.Windows.Forms.Form parentWindow, System.Windows.Forms.Form childrenWindow)
{
foreach (System.Windows.Forms.Form ff in parentWindow.MdiChildren)
{
//如果子窗体存在,激活子窗体
if (ff.Name == childrenWindow.Name)
{
ff.Activate();
ff.Size = ff.Parent.Size;
ff.WindowState = System.Windows.Forms.FormWindowState.Maximized;
//((frmMain)parentWindow).s slblOperate.Text = ff.Text;
return;
}
}
parentWindow.IsMdiContainer = true;
childrenWindow.MdiParent = parentWindow;
childrenWindow.WindowState = System.Windows.Forms.FormWindowState.Maximized;
//parentWindow.ActiveMdiChild = childrenWindow;
childrenWindow.Show();
}
调用:
openChildrenWindow(this, new Form2()); //form2需要打开的窗体