C#中避免相同MDI子窗口重复打开的方法
1: // 是否已经打开了?(用循环来判断)
2: foreach (Form childrenForm in this.MdiChildren)
3: {
4: //检测是不是当前子窗体名称
5: if (childrenForm.Name == "FormExaminee")
6: {
7: //是的话就是把他显示
8: childrenForm.Visible = true;
9: //并激活该窗体
10: childrenForm.Activate();
11: childrenForm.WindowState = FormWindowState.Maximized;
12: return;
13: }
14: }
15:
16: //如果没有打开,则新建窗体
17: FormChild.FormExaminee formExaminee = new FormChild.FormExaminee();
18: formExaminee.MdiParent = this;
19: formExaminee.WindowState = FormWindowState.Maximized;
20: formExaminee.Show();