WPF 获取鼠标全局坐标【精简】

项目名为 WPF_XFC

新建类名MouseXY

class MouseXY
    {
        [StructLayout(LayoutKind.Sequential)]
        public struct POINT
        {
            public int X;
            public int Y;

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

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern bool GetCursorPos(out POINT pt);
    }

然后调用方法

 MouseXY.POINT pi = new MouseXY.POINT();
                MouseXY.GetCursorPos(out pi);
                MessageBox.Show(pi.X.ToString() + "__" + pi.Y.ToString());

就会弹出坐标~贼鸡儿6 

这是我百度到最精简好用的获取鼠标的全局坐标的方法~

猜你喜欢

转载自www.cnblogs.com/baimangguo/p/8917186.html

相关文章