创建“鼠标悬停”对 VB TreeView 节点的影响
TreeView 控件的节点没有要测试的“鼠标悬停”属性。我希望“突出显示”该节点(向用户提供有关选择哪个节点的反馈)。
例如,当 MouseMove
事件在 TreeView
控件上触发时,我可以将节点对象设置为“HitTest
”返回的内容:
Set nde = trvChoices.HitTest(x, y * 15)
我正在寻找当鼠标悬停在该节点上方时“突出显示”该节点(或其他内容)的方法,以便向用户提供选择 TreeView 中哪个节点的反馈。是的,我使用 TreeView 作为“右键单击”菜单。我不想使用不同的控件,尽管我可能不得不......
Nodes of a TreeView control do not have a 'mouse over' property to test for. I was hoping to "highlight" the node (to give the user feedback on which one is selected).
For example, when the MouseMove
event fires on the TreeView
control, I can set a node object to what "HitTest
" returns:
Set nde = trvChoices.HitTest(x, y * 15)
I am looking for a way to have this node "highlighted" (or something) when the mouse is over it, in order to give the user feedback of which node in the TreeView is selected. Yes, I am using TreeView as a 'right-click' menu. I do not wish to use a different control, although I may have to...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
让节点在悬停时变为粗体是理所当然的。但是,将 BackColor 或 ForeColor 设置为任何颜色(例如 wdYellow)只会使整个节点变黑...
发布示例代码,以防其他人遇到此情况:
It was a no-brainer to get the node to be Bold on hover. However, setting the BackColor or ForeColor to any color e.g. wdYellow would just black out the entire node...
Posting example code in case anyone else runs into this:
我一直在尝试让 OLEDragDrop 与 Treeview 和 Listview 一起使用,但遇到了一个问题,即 StartDrag 试图在用户启动 StartDrag 之前遍历 Treeview 中处于活动状态的项目,而不是他们想要的项目。试图拖过去。我在其他地方看到过要求用户在拖动之前单击某个项目的解决方案,但这是违反直觉的。通过稍微修改您的代码,我能够将鼠标下的项目设置为活动项目:
(a) 向用户提供反馈并且
(b) 使 OLEDragDrop 正常工作。
I've been trying to get OLEDragDrop to work with a Treeview and Listview and had run into an issue where the StartDrag tried to take across the item that was active in the Treeview before the user had started the StartDrag, rather than the item that they were trying to drag across. I had seen solutions elsewhere that required the user to click on an item before dragging, but this was counterintuitive. By modifying your code slightly I was able to set the item under the mouse as the active item which:
(a) gives feedback to the user and
(b) makes the OLEDragDrop work correctly.
* 15 用于像素/缇转换。不幸的是,它并不适用于所有显示器,因为不同的显示器在像素和缇之间具有不同的速率,具体取决于显示器比率。但 15 确实符合标准
4:3
显示器。使用上面的方法来得到这个。
此外,您需要检查是否需要进行转换,因为不同版本使用不同的输出 x,y 值。
The * 15 is for pixel/twip conversion. Unfortunately it doesn't work for all monitors as different monitors have a different rate between pixel and twips depending on monitor ratio. BUT 15 does comply to standard
4:3
monitors.Use above to get this.
Additionally you need to check if you need to do the conversion at all as different versions use different output x,y values.