在VB TreeView节点上创建“鼠标悬停"效果 [英] Creating a 'mouse over' effect on a VB TreeView node
问题描述
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).
例如,当MouseMove
事件在TreeView
控件上触发时,我可以将节点对象设置为"HitTest
"返回的内容:
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)
我正在寻找一种方法,当鼠标悬停在该节点上时,使该节点突出显示"(或其他内容),以便向用户提供在TreeView中选择了哪个节点的反馈.是的,我将TreeView用作右键单击"菜单.我不希望使用其他控件,尽管我可能不得不...
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...
推荐答案
在悬停时使节点变为粗体是不费吹灰之力的.但是,将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:
Private Sub trvChoices_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS)
If Not (trvChoices.HitTest(x, y * 15) Is Nothing) Then
Dim nde As Node
Set nde = trvChoices.HitTest(x, y * 15)
'I have three nodes only, but the proper way would be to loop through the trvChoices and set each node to Bold = False
trvChoices.Nodes(1).Bold = False
trvChoices.Nodes(2).Bold = False
trvChoices.Nodes(3).Bold = False
nde.Bold = True
Set nde = Nothing
End If
End Sub
这篇关于在VB TreeView节点上创建“鼠标悬停"效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!