public void showform(Form f) { int count = 0;//用来记录是否有打开的窗体 foreach(Form ff in this.MdiChildren)//遍历容器中已经打开的窗体 { if (f.Name == ff.Name)//如果重名,说明已经存在 { ff.Focus();//将已经打开的窗体聚焦 count++;//计数 } } if (count == 0)//如果没有打开的同名窗体,第一次点击窗体时,已经打开的子窗体为空,count=0 { f.MdiParent = this;//在容器中 f.Show();//打开 } } private void 窗体一ToolStripMenuItem_Click(object sender, EventArgs e) { Form2 f = new Form2(); showform(f); } private void 窗体二ToolStripMenuItem_Click(object sender, EventArgs e) { Form3 f = new Form3(); showform(f); } private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { //首先在属性中设置ismdicontainer为true,是否为container容器 }