The child form with the same name is opened only once in the parent form

Source: Internet
Author: User

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}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.