如何从应用程序窗口获取/设置鼠标相对位置? [英] How to get/set the position of the mouse relative from the application window?
本文介绍了如何从应用程序窗口获取/设置鼠标相对位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够获取相对于我的窗体窗口所在位置的鼠标指针的当前位置。因此,如果我将鼠标放在表单的左上方,它将为我提供x = 0和y = 0的x和y值,而表单本身可能位于屏幕中间。
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.
我也想设置鼠标的位置。
如何在C#?我正在使用Windows窗体应用程序。
How can this be done in C#? I'm using a windows forms application.
推荐答案
使用 Cursor.Position ,然后转换为调用窗口上的PointToClient 。
Obtain the screen coordinates by using Cursor.Position, then convert to window coordinates invoking PointToClient on the window.
Point p = this.PointToClient(Cursor.Position);
这篇关于如何从应用程序窗口获取/设置鼠标相对位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文