当鼠标悬停在 TreeNode 上时,如何使 TreeNode 改变光标?

发布于 2024-09-09 08:04:24 字数 822 浏览 15 评论 0 原文

我使用树视图创建了一个菜单,以便在用户单击节点时启动表单。为了完成外观,我将节点设置为看起来像超链接。当用户将鼠标悬停在节点上时,我希望将光标更改为一只手(就像将鼠标悬停在链接上时看到的那样),但是到目前为止,我只能将光标在悬停在节点内部时更改树视图,而不是节点。据我所知,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

我希望有人能为我指明正确的方向来实现这一目标。本质上,我正在寻找嵌套 LinkBut​​ton 数组的外观。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野味少女 2024-09-16 08:04:24

使用鼠标移动事件。调用 HitTest() 方法。

Use the MouseMove event. Call the HitTest() method.

梦一生花开无言 2024-09-16 08:04:24

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文