WPF 获取鼠标屏幕位置、窗口位置、控件位置

public struct POINT
    {
        public int X;
        public int Y;
        public POINT(int x, int y)
        {
            this.X = x;
            this.Y = y;
        }
    }

[DllImport("user32.dll")]
public static extern bool GetCursorPos(out POINT lpPoint);

//e.GetPosition(this);
//(e.Source as FrameworkElement).PointToScreen(new Point(0, 0));            
POINT mousestart = new POINT();
GetCursorPos(out mousestart);

Point p2 = Mouse.GetPosition(this as FrameworkElement);

Point p = Mouse.GetPosition(e.Source as FrameworkElement);

MessageBox.Show(Convert.ToString(mousestart.X));
MessageBox.Show(Convert.ToString(p.X));
MessageBox.Show(Convert.ToString(p2.X));

  

WPF 获取鼠标屏幕位置、窗口位置、控件位置

上一篇:Wpf 关闭当前窗体 打开新窗体


下一篇:C# 对象转JSON字符串