C# 设置鼠标光标位置

C# 设置鼠标光标位置

1using System.Drawing; 2using System.Runtime.InteropServices; 3 4namespace ZB.QueueSys.Common 5{ 6 public class MouseHelper 7 { 8 private static MouseHelper instance; 9 public static MouseHelper Instance 10 { 11 get 12 { 13 if (instance == null) instance = new MouseHelper(); 14 return MouseHelper.instance; 15 } 16 } 17 18 /// <summary> 19 /// 引用user32.dll动态链接库(windows api), 20 /// 使用库中定义 API:SetCursorPos 21 /// </summary> 22 [DllImport("user32.dll")] 23 private static extern int SetCursorPos(int x, int y); 24 /// <summary> 25 /// 移动鼠标到指定的坐标点 26 /// </summary> 27 public void MoveMouseToPoint(Point p) 28 { 29 SetCursorPos(p.X, p.Y); 30 } 31 /// <summary> 32 /// 设置鼠标的移动范围 33 /// </summary> 34 public void SetMouseRectangle(Rectangle rectangle) 35 { 36 System.Windows.Forms.Cursor.Clip = rectangle; 37 } 38 /// <summary> 39 /// 设置鼠标位于屏幕中心 40 /// </summary> 41 public void SetMouseAtCenterScreen() 42 { 43 int winHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height; 44 int winWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width; 45 Point centerP = new Point(winWidth / 2, winHeight / 2); 46 MoveMouseToPoint(centerP); 47 } 48 49 } 50} 51 52 53调用测试如下: 54 int y = Screen.PrimaryScreen.WorkingArea.Height - 180; 55 int x = Screen.PrimaryScreen.WorkingArea.Width - 180; 56 Point p = new Point(x, y); 57 MouseHelper.Instance.MoveMouseToPoint(p);

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

1      int x = this.dgvList.Location.X; 2 int y = this.dgvList.Location.Y; 3 Point p = new Point(x, y); 4 Point pp = this.dgvList.PointToScreen(p); 5 MouseHelper.Instance.MoveMouseToPoint(pp);
点赞
收藏

评论区

加载中...

相关推荐

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

Linux终端Terminal常用快捷键

快捷键功能CTRLALTT打开终端Ctrla光标移动到开始位置Ctrle光标移动到最末尾Ctrlk删除此处至末尾的所有内容Ctrlu删除此处至开始的所有内容Ctrld删除当前字符Ctrlh删除当前字符前一个字符Ctrlw删除此处到左边的单词Ctrly粘贴由Ctrl

Flutter TextField设置默认值默认值和光标位置

主要通过controller实现,具体代码如下TextField(          //输入键盘类型keyboardType:TextInputType.text,autofocus:true,decoration:Inpu

mysql设置时区

mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0

Unity 利用射线实现弹孔效果

1、利用 Camera.main.ScreenPointToRay从屏幕到鼠标点击位置生成一条射线。2、利用 Physics.Raycast 发射射线,同时判断是否碰撞到目标物体。3、通过 RaycastHit获取射线所碰撞到的位置。4、在目标位置生成一个弹孔预设体。 具体代码:using UnityEngine;

Deepin重置管理员密码

Debian系重置管理员密码的指南网络上很多,这里针对Deepin列出步骤。关键是第3步,要在正确的位置输入内容。1.引导界面,按下“e”2.移动光标到包含“rosplashquiet”的行3.按下“Ctrle”,光标移动到行末,再把光标移动到“quiet”的后面4.按下空格键,输入“init/bin/bash”5