1 private void button1_Click( object sender, EventArgs e) 2 { 3 bool isfind = false; 4 foreach (Form fm in Application.OpenForms) 5 { 6 if (fm.Name == " Form2 ") { fm.Activate(); fm.WindowState = FormWindowState.Normal; return; } 7 } 8 if (!isfind) { Form fm = new Form2(); fm.Show(); } 9 10 }
如果是在MDI父窗口中打开好多子窗口,查找子窗口的代码: foreach (Form chform in this .MdiChildren) { if (chform.Text == " 子窗口的标题 ") { chform.Activate(); Isfind = true; } }