C# 设置鼠标光标位置
2024-08-25 04:00:01
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);
最新文章
- 手机浏览器不支持 IDBObjectStore.getAll
- VMware虚拟网络编辑器
- log4j - 配置文件
- TCP定时器
- 使用IIS 7.0 Smooth Streaming 优化视频服务
- 2016031901 - ubuntu15.1安装驱动
- show()与showDialog()的区别
- JavaScript数组的学习
- Linux内核和驱动编译常见问题
- 关于java的上转型对象
- Struts2 控制文件上传下载
- LinkedHashMap源码分析及实现LRU
- short s=1;s=s+1;short s=1;s+=1;有什么区别?
- C#连接mysql数据库的一个例子和获取本机IP的方法
- 算法学习——决策单调性优化DP
- linux 分区、目录及用途
- DIV或者DIV里面的图片水平与垂直居中的方法
- 【动态规划】最大子段和问题,最大子矩阵和问题,最大m子段和问题
- dubbo学习(zz)
- Winsock API TCP/IP网络通信
热门文章
- vmware安装密钥
- jQuery BlockUI Plugin Demo 6(Options)
- SPSS 2019年10月31日 20:20:53今日学习总结
- 【VS开发】【miscellaneous】windows(64位)下使用curl命令
- 谈谈NPM和Webpack的关系
- NOIp 2009:靶形数独
- layuiAdmin (单页版)常见问题与解决方案
- Python爬虫入门教程之BeautifulSoup
- 数据库设计_ERMaster安装使用_PowerDesigner数据设计工具
- android 自动化测试案例之 MonkeyRunner