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# 设置鼠标光标位置的更多相关文章

  1. Android 设置EditText光标位置(转)

    Android 设置EditText光标位置 最后 CharSequence text = edtTxt_my_account_edit_nickname.getText();if (text ins ...

  2. Range对象理解,浏览器兼容性,获取鼠标光标位置

    一.关于浏览器的兼容性 目前主要有3种关于range的类似的对象,分别是W3C range 对象,Mozzlia selection ,ie TextRange 关于这三种的区别,请查看文档 http ...

  3. [Android教程]EditText设置/隐藏光标位置、选中文本和获取/清除焦点

      有时候需要让光标显示在EditText的指定位置或者选中某些文本.同样,为了方便用户输入以提升用户体验,可能需要使EditText获得或失去焦点. 1. 设置光标到指定位置 EditText et ...

  4. Android 设置EditText光标位置

    Android中有很多可编辑的弹出框,其中有些是让我们来修改其中的字符,这时光标位置定位在哪里呢? 刚刚解了一个bug是关于这个光标的位置的,似乎Android原生中这种情况是把光标定位到字符串的最前 ...

  5. EditText设置/隐藏光标位置、选中文本和获取/清除焦点(转)

    转:http://blog.csdn.net/dajian790626/article/details/8464722 有时候需要让光标显示在EditText的指定位置或者选中某些文本.同样,为了方便 ...

  6. 设置鼠标光标与页面favicon

    鼠标光标 body{cursor: url('http://image.XXXX.com/ii.png'),default;} 2. favicon <link rel="shortc ...

  7. 对span设置鼠标光标样式

    <html> <body> <p>请把鼠标移动到单词上,可以看到鼠标指针发生变化:</p> <span style="cursor:au ...

  8. 设置EditText光标位置

    editext.setSelection(int index);

  9. C#-WinForm-如何获取文本框(TextBox)中鼠标,光标位置

    文本框(TextBox)中的鼠标位置和光标位置是两个不同的概念,鼠标位置是要点击鼠标后(NouseDown)获取到,而光标位置却是实时就要获取到,也就是用户输入一个字符(KeyUp),这个位置就要改变 ...

随机推荐

  1. Java测试当前应用所占用的内存示例

    package test; import java.util.HashMap; import java.util.Map; public class TestMemory { public stati ...

  2. charles 偏好设置

    本文参考:charles 偏好设置 charles 偏好设置  偏好设置,注意作用如下 用户界面 视图 启动设置 警告设置 视图选项 头和主体一起查看 请求和响应页查看 结构试图布局 序列试图布局 显 ...

  3. Ext.jsTree 向子节点添加叶子节点

    // 定义搜索节点树结构Store const nodeStore = Ext.create('Ext.data.TreeStore', { autoLoad : true, id : 'nodeSt ...

  4. 火狐低版本中显示时间格式为:yyyy-MM-dd hh:mm:ss,出现NaN

    在低版本的火狐(43以下)和IE8中,显示时间格式为:yyyy-MM-dd hh:mm:ss,会出现NaN:原因是只支持yyyy/MM/dd hh:mm:ss; 所以在new Date('2018-0 ...

  5. 提高.NET应用性能

    提高.NET应用性能的方法 写在前面 设计良好的系统,除了架构层面的优良设计外,剩下的大部分就在于如何设计良好的代码,.NET提供了很多的类型,这些类型非常灵活,也非常好用,比如List,Dictio ...

  6. Python基础——循环语句、条件语句、函数、类

    注:运行环境  Python3 1.循环语句 (1)for循环 注:for i in range(a, b):  #从a循环至b-1 for i in range(n):      #从0循环至n-1 ...

  7. git简易指南

    目录 工作流 初始化仓库 查看分支 添加和提交 推送改动 分支 重命名分支 更新与合并 替换本地改动 回滚 远程仓库 有用的贴士 GIT vs SVN 工作流 你的本地仓库由 git 维护的三棵&qu ...

  8. Spring Bean装配详解(五)

    装配 Bean 的概述 前面已经介绍了 Spring IoC 的理念和设计,这一篇文章将介绍的是如何将自己开发的 Bean 装配到 Spring IoC 容器中. 大部分场景下,我们都会使用 Appl ...

  9. 学习Electorn(1)——Hello World

    环境 操作系统是Manjaro kde 18.01 按照官网文档:https://electronjs.org/docs 安装node https://nodejs.org/en/download/p ...

  10. 箭头函数的arguments不可用

    ES5中的arguments function func(a,b,c){ console.log(arguments[0],arguments[1],arguments[2]) } func(1,2, ...