首页 > 其他 > 详细

WPF获取鼠标当前位置

时间:2014-06-27 16:54:43      阅读:417      评论:0      收藏:0      [点我收藏+]
  /// <summary>   
         /// 设置鼠标的坐标   
         /// </summary>   
         /// <param name="x">横坐标</param>   
         /// <param name="y">纵坐标</param>          

         [DllImport("User32")]

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

         }

         /// <summary>   
         /// 获取鼠标的坐标   
         /// </summary>   
         /// <param name="lpPoint">传址参数,坐标point类型</param>   
         /// <returns>获取成功返回真</returns>   


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


         private void Window_MouseMove(object sender, MouseEventArgs e)
         {
             POINT p = new POINT();
             if (GetCursorPos(out p))//API方法
            {
                 txtStat.Text = string.Format("X:{0}   Y:{1}", p.X, p.Y);
             }
         }

 

WPF获取鼠标当前位置,布布扣,bubuko.com

WPF获取鼠标当前位置

原文:http://www.cnblogs.com/gaobing/p/3810040.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!