C# 设置鼠标光标位置

using System.Drawing;
using System.Runtime.InteropServices; namespace ZB.QueueSys.Common
{
public class MouseHelper
{
private static MouseHelper instance;
public static MouseHelper Instance
{
get
{
if (instance == null) instance = new MouseHelper();
return MouseHelper.instance;
}
} /// <summary>
/// 引用user32.dll动态链接库(windows api),
/// 使用库中定义 API:SetCursorPos
/// </summary>
[DllImport("user32.dll")]
private static extern int SetCursorPos(int x, int y);
/// <summary>
/// 移动鼠标到指定的坐标点
/// </summary>
public void MoveMouseToPoint(Point p)
{
SetCursorPos(p.X, p.Y);
}
/// <summary>
/// 设置鼠标的移动范围
/// </summary>
public void SetMouseRectangle(Rectangle rectangle)
{
System.Windows.Forms.Cursor.Clip = rectangle;
}
/// <summary>
/// 设置鼠标位于屏幕中心
/// </summary>
public void SetMouseAtCenterScreen()
{
int winHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
int winWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
Point centerP = new Point(winWidth / 2, winHeight / 2);
MoveMouseToPoint(centerP);
} }
} 调用测试如下:
int y = Screen.PrimaryScreen.WorkingArea.Height - 180;
int x = Screen.PrimaryScreen.WorkingArea.Width - 180;
Point p = new Point(x, y);
MouseHelper.Instance.MoveMouseToPoint(p);

C#获取指定控件所在屏幕的位置

         int x = this.dgvList.Location.X;
int y = this.dgvList.Location.Y;
Point p = new Point(x, y);
Point pp = this.dgvList.PointToScreen(p);
MouseHelper.Instance.MoveMouseToPoint(pp);

  

  

最新文章

  1. 手机浏览器不支持 IDBObjectStore.getAll
  2. VMware虚拟网络编辑器
  3. log4j - 配置文件
  4. TCP定时器
  5. 使用IIS 7.0 Smooth Streaming 优化视频服务
  6. 2016031901 - ubuntu15.1安装驱动
  7. show()与showDialog()的区别
  8. JavaScript数组的学习
  9. Linux内核和驱动编译常见问题
  10. 关于java的上转型对象
  11. Struts2 控制文件上传下载
  12. LinkedHashMap源码分析及实现LRU
  13. short s=1;s=s+1;short s=1;s+=1;有什么区别?
  14. C#连接mysql数据库的一个例子和获取本机IP的方法
  15. 算法学习——决策单调性优化DP
  16. linux 分区、目录及用途
  17. DIV或者DIV里面的图片水平与垂直居中的方法
  18. 【动态规划】最大子段和问题,最大子矩阵和问题,最大m子段和问题
  19. dubbo学习(zz)
  20. Winsock API TCP/IP网络通信

热门文章

  1. vmware安装密钥
  2. jQuery BlockUI Plugin Demo 6(Options)
  3. SPSS 2019年10月31日 20:20:53今日学习总结
  4. 【VS开发】【miscellaneous】windows(64位)下使用curl命令
  5. 谈谈NPM和Webpack的关系
  6. NOIp 2009:靶形数独
  7. layuiAdmin (单页版)常见问题与解决方案
  8. Python爬虫入门教程之BeautifulSoup
  9. 数据库设计_ERMaster安装使用_PowerDesigner数据设计工具
  10. android 自动化测试案例之 MonkeyRunner