Click on treeview node open a new MDI form, focus left on first form

后端 未结 1 1177
耶瑟儿~
耶瑟儿~ 2021-01-29 04:23

I\'m trying to open a new form after clicking a node in a treeview.

In the first MDI form I have a treeview, when I click on a node in the tree view a 2nd MDI form is op

相关标签:
1条回答
  • 2021-01-29 04:48

    Yes, TreeView is a bit of a pain that way, it restores the focus to itself. That's why it has the AfterXxx events, but there's no AfterNodeMouseClick event. The way to solve it is to delay executing the method, until after all event side-effects are completed. That's elegantly done by using the Control.BeginInvoke() method, its delegate target runs when the UI thread goes idle again. Like this:

      private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {
          this.BeginInvoke(new Action(() => OpenClientOrAccount(e.Node)));
      }
    
    0 讨论(0)
提交回复
热议问题