Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting mouse-position relatively to a control

Tags:

c#

winforms

mouse

I'm trying to find a way to get the mouse position relatively to the upper left corner of a control, is there a way to accomplish that?

like image 600
Gilad Naaman Avatar asked Apr 12 '11 17:04

Gilad Naaman


People also ask

How do I get my mouse cursor position?

Once you're in Mouse settings, select Additional mouse options from the links on the right side of the page. In Mouse Properties, on the Pointer Options tab, at the bottom, select Show location of pointer when I press the CTRL key, and then select OK. To see it in action, press CTRL.

What is a cursor position?

The cursor position is represented by the line number and the character number and signifies where the next character will be displayed. For example, cursor position 1,1 always indicates the upper-leftmost corner position on the terminal. Cursor position 10,30 indicates the 30th character position on the 10th line.

What is mouse offset?

offset(). left of the parent div container, and calculate the difference from that to the current X and Y coordinates of the mouse cursor. . offset() always refers to the document and not to the parent of the element.

How do you get the mouse position in Pyautogui?

To determine the mouse's current position, we use the statement, pyautogui. position(). This function returns a tuple of the position of the mouse's cursor. The first value is the x-coordinate of where the mouse cursor is.


2 Answers

Call MyControl.PointToClient() passing Cursor.Position.

like image 166
David Heffernan Avatar answered Nov 15 '22 06:11

David Heffernan


yourControl.PointToClient(Control.MousePosition)

like image 45
manji Avatar answered Nov 15 '22 04:11

manji