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);

 

posted @ 2012-02-13 13:11  帕丁顿熊  阅读(1682)  评论(1编辑  收藏  举报