winfrom中,父窗体中只允许显示一个子窗体的代码怎么写?

private void ChangeChildren(Form frm)
{
//判断是否是第一次显示窗体
if (this.MdiChildren.Length == 1)
{
frm.Show();
return;
}
foreach (Form children in this.MdiChildren)
{
if (frm == children)
{
//如果是现在就存在的子窗体就激活它
children.Activate();
break;
}
else
{
//如果窗体不一样就关闭了,在显示现在所需要的
children.Close();
frm.Show();
break;
}
}
}

是这样调用的
Form f = new Form();
f.MdiParent = this;
f.Text = "1";
ChangeChildren(f);
微软BI技术交流群:316744959 武汉NET技术群:961108969 NET技术群:21386099 本人具有丰富的系统开发经验,承接系统开发,小程序,NET系统开发,BI开发,有需求联系微信手机:15010195887
原文地址:https://www.cnblogs.com/Impulse/p/1500815.html