第一种:
Form Room = new Room();//Room为新窗体名称
for(int x=0;x<this.MdiChildren.Length;x++)
{
Form tempChild = (Form)this.MdiChildren[x];
tempChild.Close();
}
Room.MdiParent = this;
Room.WindowState = FormWindowState.Maximized;
Room.Show();
第二种:
//通过窗体名称查询该窗体是否已经存在,如存在则显示,否则就新创建一个
if (this.checkChildFrmExist("SubjectSetting") == true)
{
return;
}
SubjectSetting newFrm=new SubjectSetting();//SubjectSetting为新窗体名称
newFrm.MdiParent = this;
newFrm.Show();
//----------------------查询MDI子窗体是否存在-----------------------------
private bool checkChildFrmExist(string childFrmName)
{
foreach(Form childFrm in this.MdiChildren)
{
if(childFrm.Name == childFrmName) //用子窗体的Name进行判断,如果存在则将他激活
{
if(childFrm.WindowState == FormWindowState.Minimized)
childFrm.WindowState = FormWindowState.Normal;
childFrm.Activate();
return true;
}
}
return false;
}