OK this is not rocket science, but I keep forgetting.

To get the current mouse position relative to a control, System.Windows.Forms.Control has a static MousePosition property

System.Windows.Forms.Control.MousePosition

and a PointToClient method, which will take the screen coordinats as a Point as agument, and return a the client coordinates.

Eg. in a TreeView, this can be used to get the node the mouse is pointing at, as:

TreeNode editNode = treeView.GetNodeAt(treeView.PointToClient(System.Windows.Forms.Control.MousePosition));

As always, feel free to comment, or ask.


Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading