TreeView节点被突出显示,即使我没有右键单击节点 [英] treeview node is highlighted even i did not right click on the node
问题描述
我在一个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节点被突出显示,即使我没有右键单击节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!