解决C#获取鼠标相对当前窗口坐标的实现方法
时间:2022-10-07 12:57:57
在我们编写客户端应用程序时,经常要用到鼠标当前的位置。在C#winform中,可以用Control.MousePosition获得当前鼠标的坐标,使用PointToClient计算鼠标相对于某个控件的坐标,如下
Point screenPoint = Control.MousePosition;//鼠标相对于屏幕左上角的坐标
Point formPoint = this.PointToClient(Control.MousePosition);//鼠标相对于窗体左上角的坐标
Point contextMenuPoint = contextMenuStrip1.PointToClient(Control.MousePosition); //鼠标相对于contextMenuStrip1左上角的坐标
标签:c#,获取鼠标坐标
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android SurfaceView预览变形完美解决方法
2021-11-14 10:29:22
Android Studio使用教程(五):Gradle命令详解和导入第三方包
2023-03-06 11:11:26
![](https://img.aspxhome.com/file/2023/9/106049_0s.png)
在spring boot3中使用native image的最新方法
2022-05-18 17:43:14
![](https://img.aspxhome.com/file/2023/5/89565_0s.png)
MyBatis环境资源配置实现代码详解
2023-08-05 08:59:02
Unity3D更改默认的脚本编辑器
2021-06-05 14:58:53
![](https://img.aspxhome.com/file/2023/5/68625_0s.png)
springboot如何读取自定义配置项
2021-06-18 10:44:53
使用ObjectMapper解析json不用一直new了
2023-11-25 05:20:10
![](https://img.aspxhome.com/file/2023/6/63856_0s.jpg)
Java压缩文件工具类ZipUtil使用方法代码示例
2022-11-26 02:21:32
Sentinel源码解析入口类和SlotChain构建过程详解
2022-06-14 18:29:50
![](https://img.aspxhome.com/file/2023/2/105972_0s.png)
一篇文章带你搞懂Java线程池实现原理
2021-10-23 05:45:36
![](https://img.aspxhome.com/file/2023/5/77075_0s.jpg)
java中switch选择语句代码详解
2023-09-28 19:34:29
利用@Value注解为bean的属性赋值方法总结
2023-10-15 19:54:06
java实现udp通讯的代码
2022-07-18 13:28:52
C#实现简单点餐系统
2021-06-27 22:00:56
![](https://img.aspxhome.com/file/2023/2/80122_0s.jpg)
JDBC查询Map转对象实现过程详解
2021-08-30 07:17:40
IDEA最新版2020.1的maven工程本地依赖仓库无法使用问题(已解决)
2023-09-21 17:57:00
![](https://img.aspxhome.com/file/2023/1/60831_0s.png)
SpringBoot实现文件上传与下载功能的示例代码
2021-11-10 09:15:32
java 对象输入输出流读写文件的操作实例
2021-06-13 15:24:30
unity AudioSource播放完声音后要执行的函数或条件操作
2021-07-04 21:46:37
![](https://img.aspxhome.com/file/2023/0/104330_0s.jpg)
android利用消息机制获取网络图片
2023-07-24 09:46:57
![](https://img.aspxhome.com/file/2023/2/85962_0s.jpg)