2

如何使鼠标右键选择节点?我用鼠标右键点击了它,如下所示:

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

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

4

1 回答 1

2

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

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 代码。

于 2012-07-26T19:11:00.840 回答