C#中使用GetCursorPos获取屏幕坐标

       [StructLayout(LayoutKind.Sequential)]
        public struct POINT
        {
            public int X;
            public int Y;
 
            public POINT(int x, int y)
            {
                this.X = x;
                this.Y = y;
            }
 
            public override string ToString()
            {
                return ("X:" + X + ", Y:" + Y);
            }
        }
 
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern bool GetCursorPos(out POINT pt);


使用:

 POINT currentPosition = new POINT();
                GetCursorPos(out currentPosition);
 
                System.Diagnostics.Debug.WriteLine("Current mouse point: " + currentPosition.ToString());
 
//转为客户区域坐标
                Point relativePos = itemsControl.PointFromScreen(new Point(currentPosition.X, currentPosition.Y));
posted @ 2013-07-04 09:16  muzizongheng  阅读(3567)  评论(0编辑  收藏  举报
如果我们时时忙着展现自己的知识, 将何从忆起成长所需的无知?