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),这个位置就要改变 ...
随机推荐
- iOS面试经历(个人)
1.OC的runtime运行机制1> runtime,运行时机制,它是一套C语言库2> 实际上我们编写的所有OC代码,最终都是转成了runtime库的东西,比如类转成了runtime库里面 ...
- CentOS7.5下安装nginx --项目部署
1.安装ngnix一些依赖包 [root@VM_39_157_centos ~]# yum -y install gcc gcc-c++ openssl-devel pcre-devel httpd- ...
- subplot()一个窗口画多个图
import matplotlib.pyplot as plt plt.subplot(m,n,p) m,n表示一个窗口上显示m行n列 p表示正在处理第p个区域的部分(区域编号从左到右,从上到下) f ...
- 深入理解linux内核-进程和程序
进程描述符task_struct task_struct { //进程基本信息 pid 进程id号 tgid 线程组id号,与线程组领头线程pid号相同 getpid()返回该值 tasks in ...
- TypeScript 高级类型 接口(interface)
在代码的实现或者调用上能设定一定的限制和规范,就像契约一样.通常,我们把这种契约称为接口. TypeScript的核心原则之一是对值所具有的结构进行类型检查. 有时称为“鸭式辨型法”或“结构性子类型化 ...
- GB2312、GBK、GB18030 这几种字符集的主要区别
1 GB2312-80 GB 2312 或 GB 2312-80 是中国国家标准简体中文字符集,全称<信息交换用汉字编码字符集·基本集>,又称 GB 0,由中国国家标准总局发布,1981 ...
- Python笔记002-Python编程基础概念
第二章(1):Python编程基础概念 1. Python 程序的构成 Python 程序有模块组成.一个模块对应 Python 源文件,一般后缀名是:.py. 模块有语句组成.运行 Python程序 ...
- css 样式合集
td换行: style="word-wrap:break-word;word-break:break-all;" 超长省略号: table { table-layout: fixe ...
- gmpy安装使用方法
gmpy是一种C编码的Python扩展模块,提供对GMP(或MPIR)多精度算术库的访问.gmpy 1.17是1.x系列的最终版本,没有进一步的更新计划.所有进一步的开发都在2.x系列(也称为gmpy ...
- python __enter__ 与 __exit__的作用,以及与 with 语句的关系(转)
https://blog.csdn.net/xc_zhou/article/details/80810111 python __enter__ 与 __exit__的作用,以及与 with 语句的关系