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);
posted @ 2009-06-10 20:19  凡的世界  阅读(1065)  评论(0编辑  收藏  举报