2

I am using the below code to get the current mouse position in a WPF application.

System.Drawing.Point _point = System.Windows.Forms.Control.MousePosition;

This works good. But when the user has a 125% display settings in the machine (Windows 7), the mouse position is wrong. Am I doing anything wrong?

WPF Lover
  • 299
  • 6
  • 16

1 Answers1

2

See if anything in this Blog or this Blog helps and since you are using Wpf try using Mouse.GetPosition as in this modified MSDN example:

// displayArea is the main window and txtBoxMousePosition is
// a TextBox used to display the position of the mouse pointer.

private void Window_MouseMove(object sender, MouseEventArgs e)
{
    Point position = Mouse.GetPosition(this);
    txtBoxMousePosition.Text = "X: " + position.X + "\n" + "Y: " + position.Y; 
}
Mark Hall
  • 53,938
  • 9
  • 94
  • 111
  • The first link (http://www.switchonthecode.com/tutorials/wpf-snippet-reliably-getting-the-mouse-position) is especially helpful, since I ran into the `Mouse.GetPosition()` not quite working issue. – seeker Aug 02 '12 at 19:26