如何获取/设置鼠标相对于应用程序窗口的位置?

发布于 2024-08-10 16:51:52 字数 173 浏览 2 评论 0原文

我希望能够获取鼠标指针相对于表单窗口所在位置的当前位置。因此,如果我将鼠标放在表单的左上角,它会给我 x=0 和 y=0 的 x 和 y 值,而表单本身可能位于屏幕中间。

我还想设置鼠标的位置。

在 C# 中如何做到这一点?我正在使用 Windows 窗体应用程序。

I want to be able to get the current location of the mouse pointer, relative from where my form window is. So if I would put my mouse on the top left of the form, it would give me the x and y values of x=0 and y=0, while the form itself might be in the middle of the screen.

Also I want to set the position of the mouse.

How can this be done in C#? I'm using a windows forms application.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失去的东西太少 2024-08-17 16:51:52

Obtain the screen coordinates by using Cursor.Position, then convert to window coordinates invoking PointToClient on the window.

Point p = this.PointToClient(Cursor.Position);
︶葆Ⅱㄣ 2024-08-17 16:51:52

查看 Cursor.Position财产

Check out the Cursor.Position property

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文