当前位置: 移动技术网 > IT编程>开发语言>c# > c# TreeView添加右键快键菜单有两种方法

c# TreeView添加右键快键菜单有两种方法

2019年07月18日  | 移动技术网IT编程  | 我要评论
一种就是使用treeview的contextmenustrip属性,添加一个新contextmenustrip,这个方法非常的简答直接,缺点是右键菜单是整个控件响应的,也就

一种就是使用treeview的contextmenustrip属性,添加一个新contextmenustrip,这个方法非常的简答直接,缺点是右键菜单是整个控件响应的,也就是说即使没有右键选中节点也是会触发快捷菜单的显示

这种方法里获取哪一个的node选中是通过这个方法:

复制代码 代码如下:

treenode curnode = this.trvfolder.getnodeat(e.x, e.y)

另一种是创建contextmenustrip,并且使用treeview的nodemouseclick事件,在事件中实现为:
复制代码 代码如下:

private void trvfolder_nodemouseclick(object sender, treenodemouseclickeventargs e)
        {
            if (e.button == mousebuttons.right)
            {
                point pos = new point(e.node.bounds.x + e.node.bounds.width, e.node.bounds.y + e.node.bounds.height / 2);
                this.cmsfoldermenu.show(this.trvfolder, pos);
            }
}

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网