I have a project in WPF 4 and vb.net 2010.
I have a canvas inside a window. The window is full screen, but the canvas is set to a solid 640x480 in the center of the window. I need to get the mouse position inside of the canvas, but NOT inside of the window. How do I do this?
The dimension of the canvas is found using the getBoundingClientRect() function. This method returns the size of an element and its position relative to the viewport. The position of x-coordinate of the mouse click is found by subtracting the event's x position with the bounding rectangle's x position.
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.
getPointerInfo(). getLocation() might be helpful. It returns a Point object corresponding to current mouse position. getPointerInfo().
The moveTo() function will move the mouse cursor to the X and Y integer coordinates you pass it.
Doesn't this work?
Point p = Mouse.GetPosition(canvas);
The position of the mouse pointer is calculated relative to the specified element with the upper-left corner of element being the point of origin,
Hi the important thing is the
NOT on the Window
the canvas is part of the window as well. one example:
... so if you start the application you will see Nothing now tell me how to get the mouseposition on the screen in pixel
!Warning! if you juse Mouse.GetPosition(this);
it will return x0 y0 every time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With