Why does the form appear behind the form of the tree when a non-mode form is activated by clicking the node of the tree?

Source: Internet
Author: User

Treeview is used in the window application. net friends may all have this problem, that is, they add the event treeviewmediaafterselect to the Treeview. In this event, open a non-mode form, which will appear behind the form where the Treeview is located, I think everyone knows the reason. I will not say much about it. The question is, how can we make the form display normally in the front of the activated window. I have the following code to achieve this. You can refer to it and tell me what problems you have:

Private delegate void dlgproc (string path); // declares a proxy to execute an asynchronous operation.
Private void treeviewappsafterselect (Object sender, system. Windows. Forms. treevieweventargs E)
{
String Path = NULL; // used to display the title of the opened form

Treenode node = This. treeview1.selectednode;
If (node! = NULL)
{
Path = node. text;
While (node. parent! = NULL)
{
Node = node. parent;
Path = node. Text + "//" + path;
}
Dlgproc dp = new dlgproc (this. thproc); // declare the proxy instance
DP. begininvoke (path, null, null); // start asynchronous operations
}
}

Private void thproc (string path) // method executed during asynchronous calling
{
Dlgproc dp = new dlgproc (opensubform); // declare a proxy to execute the method in the original thread
This. Invoke (DP, new object [] {path}); // use invoke to call the method of opening a form in the original thread.
}

Private void opensubform (string path)
{
Formsub F = new formsub (); // form to be opened
F. Text = path; // pass a value
This. addownedform (f); // you can skip this sentence. here you just want to add a subform.
F. Show (); // The displayed form is normal :)
}

In fact, the principle is very simple, that is, to open the form with an asynchronous method that is irrelevant to the treeviewmediaafterselect statement. The form is naturally displayed normally and is no longer affected by the treeviewmediaafterselect event.

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.