C# 设置鼠标光标位置
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);
C# 设置鼠标光标位置的更多相关文章
- Android 设置EditText光标位置(转)
Android 设置EditText光标位置 最后 CharSequence text = edtTxt_my_account_edit_nickname.getText();if (text ins ...
- Range对象理解,浏览器兼容性,获取鼠标光标位置
一.关于浏览器的兼容性 目前主要有3种关于range的类似的对象,分别是W3C range 对象,Mozzlia selection ,ie TextRange 关于这三种的区别,请查看文档 http ...
- [Android教程]EditText设置/隐藏光标位置、选中文本和获取/清除焦点
有时候需要让光标显示在EditText的指定位置或者选中某些文本.同样,为了方便用户输入以提升用户体验,可能需要使EditText获得或失去焦点. 1. 设置光标到指定位置 EditText et ...
- Android 设置EditText光标位置
Android中有很多可编辑的弹出框,其中有些是让我们来修改其中的字符,这时光标位置定位在哪里呢? 刚刚解了一个bug是关于这个光标的位置的,似乎Android原生中这种情况是把光标定位到字符串的最前 ...
- EditText设置/隐藏光标位置、选中文本和获取/清除焦点(转)
转:http://blog.csdn.net/dajian790626/article/details/8464722 有时候需要让光标显示在EditText的指定位置或者选中某些文本.同样,为了方便 ...
- 设置鼠标光标与页面favicon
鼠标光标 body{cursor: url('http://image.XXXX.com/ii.png'),default;} 2. favicon <link rel="shortc ...
- 对span设置鼠标光标样式
<html> <body> <p>请把鼠标移动到单词上,可以看到鼠标指针发生变化:</p> <span style="cursor:au ...
- 设置EditText光标位置
editext.setSelection(int index);
- C#-WinForm-如何获取文本框(TextBox)中鼠标,光标位置
文本框(TextBox)中的鼠标位置和光标位置是两个不同的概念,鼠标位置是要点击鼠标后(NouseDown)获取到,而光标位置却是实时就要获取到,也就是用户输入一个字符(KeyUp),这个位置就要改变 ...
随机推荐
- nginx利用fastcgi_cache模块缓存
nginx不仅有个大家很熟悉的缓存代理后端内容的proxy_cache,还有个被很多人忽视的fastcgi_cache.proxy_cache的作用是缓存后端服务器的内容,可能是任何内容,包括静态的和 ...
- 在Electron运行的子页面无法访问window.opener解决方案
我们的首页有一个window.open打开子页面后反向刷新父页面的功能,但是主页面如果开启了nodeIntegration=true,这个时候再设置nativeWindowOpen是不启作用的.再被w ...
- CEIWEI USBMonitor监控驱动 OCX/SDK USB 监控精灵 USB过滤驱动
CEIWEI USBMonitor监控精灵软件SDK USBMonitorX.dll SDK,能够嵌入到你的App程序中,从而在你的App中实现USB端口协议分析.调试USB设备的协议信息,并可以拦截 ...
- ubuntu desktop 登录root账户
有一些操作,登录root账户比较方便,但是ubuntu桌面版默认不允许这样,需要更改root账户的默认密码才可以登录,解决方法是按以下顺序输入: sudo passwd <你现在的用户的密码&g ...
- Python 实现二分查找(递归版)
二分查找 为什么使用二分查找: python中的列表,一般取值为遍历这个列表,直到取到你想要的值,但是如果你的列表是一个有着百万元素的列表呢,那样for循环遍历列表就会很慢,可能会循环几十万次,才能找 ...
- Max coverage disjoint intervals
Assume you have k<=10^5 intervals [a_i, b_i] \in [1,10^18] (some of them may overlap), and you ne ...
- Linux_Ubantu下编译c++文件
1. 编译单个文件 利用cmake进行编译 首先在项目文件夹中创建.cpp文件 利用最简单的 hello world #include<iostream> using namespace ...
- 20191011-构建我们公司自己的自动化接口测试框架-Util的AssertResult模块
AssertResult主要就是进行结果断言的了,因为断言结果分2种情况,一种是断言词,一种是断言sheet,如果涉及断言sheet,则需要操作excel到对应的断言表断言所有的字段并且书写断言结果主 ...
- gdb调试命令总结
常用命令: l 列出源代码 每次默认列10行 list 行号 列出从第几行开始的源代码 list函数名 列出某个函数的源代码 r 运行程序 next(或n) 执行下一行语句 ...
- spring cloud微服务实践七
在spring cloud 2.x以后,由于zuul一直停滞在1.x版本,所以spring官方就自己开发了一个项目 Spring Cloud Gateway.作为spring cloud微服务的网关组 ...