TreeView节点被突出显示,即使我没有右键单击节点

编程入门 行业动态 更新时间:2024-10-25 01:23:09
本文介绍了TreeView节点被突出显示,即使我没有右键单击节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在一个winform和我的用户界面的工作有一个TreeView,我发现树节点将被突出显示,即使我没有点击右键鼠标(例如,当我点击下面的节点1将突出显示的节点上位置),但我真的不因为我想表现出不同的上下文菜单的时候我没有上一个TreeNode点击喜欢这种行为

+的RootNode

| _节点1 [右键点击这里,节点1将突出显示] | | _节点2 [右键点击这里,节点2将被突出显示]

解决方案

我已经找到另一种方法来防止节点成为亮点,当用户未在节点上单击,我只加时设置的背景色和前景色为每个节点它树

newNode.BackColor = treeview1.BackColor; newNode.ForeColor = treeview1.ForeColor; treeview1.Nodes.Add(newNode);

然后在MouseDown事件中,设置SelectedNode属性如下

私人无效treeView1_MouseDown(对象发件人,MouseEventArgs E) {树节点节点= treeView1.GetNodeAt(e.Location); 如果(节点= NULL&放大器;!&安培; Node.Bounds.Contains(e.Location)) treeView1.SelectedNode =节点; ,否则 treeView1.SelectedNode = NULL; }

I am working on a winform and on my UI there is a treeview, I found that the treenode will be highlighted even I did not click on the node by right mouse (eg, Node1 will be highlighted when I click on the following position), but i really do not like this behavior because I want to show a different context menu when I did not click on a treenode

+RootNode

|_ Node1 [ Right Click Here, Node1 will be highlighted] | |_ Node2 [ Right Click Here, Node2 will be highlighted]

解决方案

I have found another method to prevent the node to be highlight when the user not click on the node, and I only set the BackColor and ForeColor for each of the node when adding it to the tree

newNode.BackColor = treeview1.BackColor; newNode.ForeColor = treeview1.ForeColor; treeview1.Nodes.Add(newNode);

Then in the MouseDown event, set the SelectedNode property as following

private void treeView1_MouseDown(object sender, MouseEventArgs e) { TreeNode Node = treeView1.GetNodeAt(e.Location); if (Node != null && Node.Bounds.Contains(e.Location)) treeView1.SelectedNode = Node; else treeView1.SelectedNode = null; }

更多推荐

TreeView节点被突出显示,即使我没有右键单击节点

本文发布于:2023-10-31 01:44:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544621.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   右键   使我   单击   TreeView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!