Articles in this section
Category / Section

How to synchronize a button click event and cursor position on a node in WinForms TreeViewAdv?

1 min read

Synchronize a button click event and cursor position on a node

When the button is clicked, the mouse cursor can be positioned appropriately on the respective node by getting the coordinates of the TreeNodeAdv by using PointToScreen method of treeViewAdv.

C#

//Provides the coordinates of the top-left corner of a TreeNodeAdv in terms of screen coordinates.
private Point MousePointer(TreeNodeAdv node)
{
   Point point = this.treeViewAdv1.PointToScreen(this.treeViewAdv1.NodeToPoint(node));
   point = new Point (point.X+node.NodeX, point.Y);
   return point;
}
//Coding for the cursor position on a node when a button is clicked.
private void button1_Click(object sender, System.EventArgs e)
{
   Cursor.Position = this.MousePointer (this.treeViewAdv1.Nodes[0]);
}

VB

'Provides the coordinates of the top-left corner of a TreeNodeAdv in terms of screen coordinates.
Private Function MousePointer(ByVal node As TreeNodeAdv) As Point
   Dim point As Point = Me.treeViewAdv1.PointToScreen(Me.treeViewAdv1.NodeToPoint(node))
   point = New Point (point.X+node.NodeX, point.Y)
   Return point
End Function
'Coding for the cursor position on a node when a button is clicked.
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
   Cursor.Position = Me.MousePointer (Me.treeViewAdv1.Nodes(0))
End Sub

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied