码迷,mamicode.com
首页 > 其他好文 > 详细

WPF获取鼠标当前位置

时间:2014-06-27 16:55:03      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   tar   ext   

  /// <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获取鼠标当前位置

标签:style   class   blog   code   tar   ext   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!