我使用树视图创建了一个菜单,以便在用户单击节点时启动表单。为了完成外观,我将节点设置为看起来像超链接。当用户将鼠标悬停在节点上时,我希望将光标更改为一只手(就像将鼠标悬停在链接上时看到的那样),但是到目前为止,我只能将光标在悬停在节点内部时更改树视图,而不是节点。据我所知,TreeNode 没有诸如 MouseEnter 之类的事件,因此我无法让它们自己处理事件。
我试图使用此函数循环遍历节点并根据光标的 Point 属性检查 TreeNode 的 Bounds 属性,但到目前为止 If
块始终计算为 false,这意味着光标永远不会改变。
Private Sub uxNavigationTreeView_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxNavigationTreeView.MouseHover
For Each node As TreeNode In uxNavigationTreeView.Nodes
For Each child As TreeNode In node.Nodes
If child.Bounds.IntersectsWith(New Rectangle(Cursor.Position, New Size(1, 1))) Then
Me.Cursor = Cursors.Hand
End If
Next
Next
End Sub
我希望有人能为我指明正确的方向来实现这一目标。本质上,我正在寻找嵌套 LinkButton 数组的外观。
I have created a menu using a treeview to launch forms when the user clicks on a node. To complete the look-and-feel, I have set up the nodes to look like hyperlinks. I'd like to have the cursor change to a hand (like the one you see when you hover over a link) when the user hovers over a node, however so far I've only been able to have the cursor change on hovering inside the treeview, as opposed to over a node. As far as I can tell, a TreeNode doesn't have events such as MouseEnter, so I can't have them handle the events themselves.
I am attempting to use this function to loop through the nodes and check the Bounds property of the TreeNode against the Point property of the cursor, but so far the If
block always evaluates to false, meaning that the cursor never changes.
Private Sub uxNavigationTreeView_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxNavigationTreeView.MouseHover
For Each node As TreeNode In uxNavigationTreeView.Nodes
For Each child As TreeNode In node.Nodes
If child.Bounds.IntersectsWith(New Rectangle(Cursor.Position, New Size(1, 1))) Then
Me.Cursor = Cursors.Hand
End If
Next
Next
End Sub
I was hoping that someone could point me in the right direction to accomplish this. In essence, I am looking for the look-and-feel of a nested LinkButton array.
发布评论
评论(2)
使用鼠标移动事件。调用 HitTest() 方法。
Use the MouseMove event. Call the HitTest() method.
Cursor.Position 返回屏幕坐标中的鼠标指针位置 - 使用 uxNavigationTreeView。PointToClient 将位置转换为客户端坐标,我想你会更幸运。
Cursor.Position returns the mouse pointer position in screen coordinates - use uxNavigationTreeView.PointToClient to convert the position to client coordinates and I think you'll then have more luck.