WPF中获取鼠标相对于桌面位置

Posted lonelyxmas

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF中获取鼠标相对于桌面位置相关的知识,希望对你有一定的参考价值。

原文:WPF中获取鼠标相对于桌面位置

var transform = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice;
var mouse = transform.Transform(GetMousePosition());

public System.Windows.Point GetMousePosition()
{
    System.Drawing.Point point = System.Windows.Forms.Control.MousePosition;
    return new System.Windows.Point(point.X, point.Y);
}

 

或者用PointToScreen

以上是关于WPF中获取鼠标相对于桌面位置的主要内容,如果未能解决你的问题,请参考以下文章