The .NET friends who have used TreeView in the Window application may have such a problem, that is, add event treeView1_afterselect to TreeView, open a non-mode form in this event, this window appears in the form of TreeView Behind, I think I may know, I don't have much to say, how can I make this form normal display to the most exact window. I have the following code, I can do this. Everyone can See if you have any questions, you can tell me, huh, huh:
private delegate void dlgProc (string path); // declares an agent to perform an asynchronous operation .private void treeView1_AfterSelect (object sender, System.Windows.Forms.TreeViewEventArgs e) {string path = null; // for displaying On the header of the open 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); // Declaration Agent Instance DP.BeginInvoke (Path, NULL, NULL); // Start Perform Asynchronous Operation}}
Private Void Thproc (String Path) // Methods Performed during Asynchronous Call {DLGPROC DP = New DLGPROC (OpenSubform); // Declare a proxy to implement the method of the original thread this.Invoke (DP, new object [] {PATH }); // Here, use Invoke to call the method of opening the form in the original thread}
Private Void OpenSubform (String Path) {FormSub f = New Formsub (); // To open form f.text = path; // pass a value this.addownedform (f); / / Don't this sentence, here just I want to add a child form. F.show (); // The form shown here is normal :)}
In fact, the reason is very simple, that is to open the form with another asynchronous asynchronous asynchronous to do TreeView1_AFTersect, and the form is naturally normal display and no longer affected by TreeView1_AFTerselect.