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