相对于应用程序的游标位置 [英] Cursor Position relative to Application

查看:96
本文介绍了相对于应用程序的游标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何获取光标的位置:

I know how to get the cursor's position :

 int X = Cursor.Position.X;
 int Y = Cursor.Position.Y;

但这是相对于屏幕。如何获取相对于我的表单的坐标?

But this is relative to the screen. How do i get the coordinates relative to my Form?

推荐答案

使用 Control.PointToClient 方法。假设这个指向有问题的表单:

Use the Control.PointToClient method. Assuming this points to the form in question:

var relativePoint = this.PointToClient(new Point(X, Y));

或者:

var relativePoint = this.PointToClient(Cursor.Position);

这篇关于相对于应用程序的游标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆