How to enable the MDI subform to be opened repeatedly

Source: Internet
Author: User

Many friends hope that the MDI child form will not be opened repeatedly. If the child form has been created, activate it instead of creating another MDI child form, in fact, the MdiChildren attribute provided by C # can solve this problem. Let's assume a treeview control and click the corresponding node on the treeview to create an MDI subform named after this node, if the child form has been created, activate it and display it at the beginning of all child forms. The Code is as follows:

Private void treeView_AfterSelect (object sender, System. Windows. Forms. TreeViewEventArgs e)

{

System. String str = treeView. SelectedNode. Text; // obtain the text value of the corresponding treeview node.

Bool remark = true;

For (int I = 0; I <this. mdichil.pdf. Length; I ++)

If (this. mdichil1_[ I]. Name. Equals (str) // check whether the same MDI subform exists.

{

This. mdichil1_[ I]. Activate (); // The subform has been created and activated.

Remark = false;

Break;

}

If (remark) // creates a subform

{

Form2 temp_form = new Form2 ();

Temp_form.MdiParent = this;

Temp_form.Name = str;

Temp_form.Text = str;

Temp_form.Show ();

}

}

 

If there are many forms (for example, form2, form3, form4, and so on) to be created, you can use a switch to determine which one to create.

 

Another way is to determine the sub-form handle. For details, refer to the content of the "yuweng column" blog in CSDN. I will not repeat it here.

You can also view my other blog

How to enable the form to be opened without repeating

Http://blog.csdn.net/tjvictor/archive/2007/01/18/1486420.aspx

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.