TreeView_NodeMouseClick处理程序

时间:2012-07-26 18:57:07

标签: c# winforms treeview

如何通过鼠标右键选择节点? 我按下这个鼠标右键点击它:

private void myTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) 
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                this.myTreeView.SelectedNode = e.Node;
            }
        }

我希望节点不是通过点击选择,而只是按下按钮。

1 个答案:

答案 0 :(得分:1)

我猜你正在寻找这样的东西:

void myTreeView_MouseDown(object sender, MouseEventArgs e) {
  if (e.Button == MouseButtons.Right) {
    TreeNode tn = myTreeView.GetNodeAt(e.Location);
    if (tn != null) {
      myTreeView.SelectedNode = tn;
    }
  }
}

订阅TreeView的MouseDown事件并注释掉NodeMouseClick代码。