【问题标题】:Wrong Mouse position with different DPI settings in WPFWPF 中具有不同 DPI 设置的错误鼠标位置
【发布时间】:2012-06-06 04:18:59
【问题描述】:

我正在使用下面的代码来获取 WPF 应用程序中的当前鼠标位置。

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

这很好用。但是当用户在机器上有125%的显示设置(Windows 7)时,鼠标位置是错误的。我做错什么了吗?

【问题讨论】:

    标签: wpf mouse dpi


    【解决方案1】:

    看看这个Blog 或这个Blog 中是否有任何帮助,因为您使用的是 Wpf,请尝试使用 Mouse.GetPosition,如修改后的 MSDN 示例中所示:

    // 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; 
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多