执行NodeMouseClick无效

时间:2018-07-26 22:41:06

标签: c# treeview

进入load_form我要以编程方式运行Microsoft树视图的NodeMoseClick事件,例如:

  var selectedNode = tvProjectList.SelectedNode;
  TreeNodeMouseClickEventArgs treeNodeMouseClickEventArgs = new TreeNodeMouseClickEventArgs(selectedNode, MouseButtons.Left, 1, 1, 1);
  tvProjectList.Select();

     tvProjectList.NodeMouseClick += tvProjectList_NodeMouseClick;

当我调试代码并单击此行并按继续时,只是不执行方法tvProjectList_NodeMouseClick

知道为什么会这样吗?

1 个答案:

答案 0 :(得分:0)

在下面的行NodeMouseClick中。

tvProjectList.NodeMouseClick += tvProjectList_NodeMouseClick;

要实际调用该事件,您必须执行以下操作:

var selectedNode = tvProjectList.SelectedNode;
TreeNodeMouseClickEventArgs treeNodeMouseClickEventArgs = new TreeNodeMouseClickEventArgs(selectedNode, MouseButtons.Left, 1, 1, 1);
tvProjectList.Select();

tvProjectList.NodeMouseClick += tvProjectList_NodeMouseClick;

tvProjectList_NodeMouseClick(this, treeNodeMouseClickEventArgs);

要记住的一件事是,由于您刚初始化,因此实际上您可能有一个tvProjectList.SelectedNode的{​​{1}}。