Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cursor Position relative to Application

Tags:

I know how to get the cursor's position :

 int X = Cursor.Position.X;
 int Y = Cursor.Position.Y;

But this is relative to the screen. How do i get the coordinates relative to my Form?

like image 733
Mordacai1000 Avatar asked Oct 03 '13 16:10

Mordacai1000


People also ask

What is the position of cursor?

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.

How can I track my cursor in CSS?

Declare two CSS variables, --x and --y, used to track the position of the mouse on the button. Declare a CSS variable, --size, used to modify the gradient's dimensions. Use background: radial-gradient(circle closest-side, pink, transparent); to create the gradient at the correct position. Use Document.

How do I get my mouse position in react?

To get the mouse position in React: Set the onMouseMove prop on an element or add an event listener on the window object. Provide an event handler function. Access relevant properties on the event object.


2 Answers

Use the Control.PointToClient method. Assuming this points to the form in question:

var relativePoint = this.PointToClient(new Point(X, Y));

Or simply:

var relativePoint = this.PointToClient(Cursor.Position);
like image 56
lc. Avatar answered Oct 15 '22 07:10

lc.


I would use PointToClient like this:

Point p = yourForm.PointToClient(Cursor.Position);
//if calling it in yourForm class, just replace yourForm with this or simply remove it.
like image 28
King King Avatar answered Oct 15 '22 09:10

King King