首页 > 代码库 > WPF获取鼠标当前位置
WPF获取鼠标当前位置
/// <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); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。