I have an application with two windows, window A and window B. Window A has a button called CoordinateButton that I pass to the following function:
private Point FindCoordinates(UIElement CoordinateButton)
{
return System.Windows.Input.Mouse.GetPosition(CoordinateButton);
}
If I click on the button in Window A, this function returns a Point with small numbers like (15, 12), meaning that I am 15 pixels to the right of the top left corner of the button, and 12 pixels below - the cursor is really close to the measurement point.
If I click on a button in Window B, Window A will again call the function, and pass in the CoordinateButton. Even if the cursor is only a few pixels away from the CoordinateButton, GetPosition( ) still returns crazy values like (-1125, -2076), but the actual mouse is definitely within 100 pixels of the button. Any idea what is happening?
I've also tried calculating the difference using things like
System.Windows.Forms.Cursor.Position - element.PointToScreen(new Point(0,0))
but my calculation ends up a few dozen pixels off.
I have also looked into scaling suggestions like https://stackoverflow.com/a/26549677/5617177 , but they had no effect.