wpf 获取鼠标坐标

  1. PointToScreen(Mouse.GetPosition(this));
  2. Win32 API GetCursorPos

         用法:

     [StructLayout(LayoutKind.Sequential)]
        public struct POINTt
        {
            public int X;
            public int Y;

 

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

 

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

 

       例子:

     POINTt pp = new POINTt();
         GetCursorPos(out pp);
         Point p = new Point(pp.X, pp.Y);

 

你可能感兴趣的:(WPF)