右击选择的.Net树节点 [英] Right click select on .Net TreeNode

查看:156
本文介绍了右击选择的.Net树节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图显示弹出菜单我的TreeView当用户右击 - 让他们选择应用对所选节点上下文敏感的动作

I am trying to show a popup menu on my treeview when users right click - allowing them to choose context sensitive actions to apply against the selected node.

在。那一刻,用户必须左键单击节点,然后点击鼠标右键,选择

At the moment the user has to left click node and then right click to choose.

是否有可能使一个节点上单击右键选择节点 - 如果有的话是什么最好的方法来做到这一点。

Is it possible to make a right click on a node select that node - and if so what is the best method to do this.

推荐答案

左侧和右侧点击触发一个click事件,并导致选择改变。然而,在某些情况下(即我还没有打扰跟踪下)的选择将从被右点击到最初选择的节点的节点改变

Both left and right clicks fire a click event and cause the selection to change. However, in certain circumstances (that I haven't yet bothered to trace down) the selection will change from the node that was right clicked to the originally selected node.

treeView.MouseDown += (sender, args) =>
    treeView.SelectedNode = treeView.GetNodeAt(args.X, args.Y);



好一点,因为其他海报之一指出的那样,是使用 NodeMouseClick 事件:

treeView.NodeMouseClick += (sender, args) => treeView.SelectedNode = args.Node;

这篇关于右击选择的.Net树节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆