I encountered this problem when studying winform over the past two days. The solution is easy to understand.
You only need to add a bool value to implement control.
1 Private Static void openchildrenwindow (Form parentform, form childrenform)
2 {
3
4 bool flag = false;
5 form [] cform = parentform. mdichil.pdf;
6
7 foreach (Form FF in cform)
8 {
9 // if the child form with the same name already exists, the flag is equal to true and the child form is activated. After that, childrenform. Show () in the IF judgment will not be executed again.
10 if (FF. Name = childrenform. Name)
11 {
12 flag = true;
13 ff. Activate ();
14 ff. size = parentform. size;
15 ff. windowstate = formwindowstate. normal;
16 break;
17
18}
19}
20 if (flag = false)
21 {
22 childrenform. mdiparent = parentform;
23 childrenform. windowstate = formwindowstate. normal;
24 childrenform. Show ();
25}
26
27}