简体   繁体   English

获取SharpDX在鼠标相对于窗口的位置

[英]Get Mouse Position in SharpDX relative to window

How can I get the Position of the Cursor in C# relative to the window im in? 如何获得C#中光标相对于窗口im的位置?
I am using SharpDX and i tried 我正在使用SharpDX并尝试

System.Drawing.Point loc = Cursor.Position;

and

System.Drawing.Point loc = Control.MousePosition;  

which gave me the absolute X and Y Coordinates of the Cursor (X:0 and Y:0 being in the top left corner of my screen and not my window). 这给了我游标的绝对X和Y坐标(X:0和Y:0在屏幕的左上角,而不是窗口的左上角)。

Is there something implemented in SharpDX to get this done? SharpDX中是否有实现此目的的工具?
I found nothing that worked for me on the internet 我在互联网上找不到对我有用的东西

Assume you are using a winform? 假设您使用的是winform? If so, look for mouse events for controls. 如果是这样,请查找控件的鼠标事件。

If you are not using Visual studio then you will have to add the event. 如果您不使用Visual Studio,则必须添加事件。 The controls sample can be found here -> https://msdn.microsoft.com/en-us/library/system.windows.forms.control.mousemove(v=vs.110).aspx 控件示例可以在这里找到-> https://msdn.microsoft.com/zh-cn/library/system.windows.forms.control.mousemove(v=vs.110).aspx

Sharpdx does not itself deal with mouse at all from my recollection. 从我的回忆中,Sharpdx本身根本不处理鼠标。 You need to understand the field of movement for the mouse within the window and convert to what ever input stream you need. 您需要了解窗口内鼠标的运动范围,并转换为所需的输入流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM