using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 新建窗体 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void 这是一ToolStripMenuItem_Click(object sender, EventArgs e) { bool has = false; Form2 f2 = new Form2(); f2.WindowState = FormWindowState.Maximized;//最大化窗口 foreach (Form f in this.MdiChildren) { if (f.Name == f2.Name)//这是名字相同,已经打开后在打开 { has = true; f.WindowState = FormWindowState.Maximized;//最大化窗口 f.Show(); f2.Close(); } } if (has) { foreach (Form f in this.MdiChildren) { if (f.Name != f2.Name)//打开的名字不同,隐藏第一个 { f.Hide();//隐藏 } } } else //第一次打开窗口 { f2.WindowState = FormWindowState.Maximized;//最大化窗口 f2.MdiParent = this;//获取此窗口的父及窗口 f2.Show();//显示 } } private void 这是二ToolStripMenuItem_Click(object sender, EventArgs e) { bool has = false; Form3 f3 = new Form3(); f3.WindowState = FormWindowState.Maximized;//最大化窗口 foreach (Form f in this.MdiChildren) { if (f.Name == f3.Name) { has = true; f.WindowState = FormWindowState.Maximized;//最大化窗口 f.Show(); f3.Close(); } } if (has) { foreach (Form f in this.MdiChildren) { if (f.Name != f3.Name) { f.Hide(); } } } else { f3.WindowState = FormWindowState.Maximized;//最大化窗口 f3.MdiParent = this;//获取此窗口的父及窗口 f3.Show(); } } } }