private void 窗口1ToolStripMenuItem_Click(object sender, EventArgs e)
{
//方式1:子窗体会重复打开
//FrmChild1 child1 = new FrmChild1();
//child1.MdiParent = this;
//child1.Show();
//方式2:子窗体不会重复打开
bool flag = true;
foreach (Form item in this.MdiChildren)
{
if (item.Name == "FrmChild1")
{
item.Activate();
item.WindowState = FormWindowState.Normal;
item.Show();
flag = false;
break;
}
}
if (flag == true)
{
FrmChild1 child1 = new FrmChild1();
child1.Name = "FrmChild1";
child1.MdiParent = this;
child1.Show();
}
}
C#Winform不重复的显示子窗体
本文转载:CSDN博客