views:

32

answers:

2

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.

+1  A: 

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.

Will A
I'll give that a shot tomorrow. Off work for the day. Thanks.
Caleb Thompson
+1  A: 

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

Hans Passant
The event isn't firing.
Caleb Thompson
You have a control that doesn't raise the MouseMove event?? Abandon all hope.
Hans Passant
Sorry, was using the wrong MouseMove event. That worked really well. Thanks.
Caleb Thompson