如何获得实时光标坐标 [英] How Do I Get The Realtime Cursor Coordinates

查看:97
本文介绍了如何获得实时光标坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



关于来自Windows窗体的X / Y坐标的问题。

目前我使用以下方法检索正确的坐标代码如下。



 受保护 覆盖  void  OnMouseMove(MouseEventArgs e)
{
base .OnMouseMove (E);
MouseMove_X_Horizo​​ntal = e.X;
MouseMove_Y_Vertical = e.Y;
this .X_Coordinates.Text = e.X.ToString();
this .Y_Coordinates.Text = e.Y.ToString();
}





当我将鼠标移到图片框或文本标签上时我不再得到任何反馈,只有当我在没有传递任何物体的情况下将它移动到窗体周围。



即使鼠标在物体上移动,鼠标的实际坐标是否有可能过于复杂?



我已经尝试了一些像

 Cursor.GetPosition 



这个选项的结果相同。



你能不能给我一点正确的方向?



提前致谢

解决方案

你已经有了这些坐标;他们在 MouseEventArgs 实例中找到你:

https://msdn.microsoft.com/en-us/library/system.windows.forms.mouseeventargs%28v=vs.110% 29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.windows.forms.mouseeventargs.location(v = vs.110)的.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.windows.forms.mouseeventargs .x(v = vs.110).aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.windows.forms.mouseeventargs.y( v = vs.110).aspx [ ^ ]。



如果需要,可以执行坐标转换,从控制到屏幕反之亦然:

https://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoscreen(v = vs.110).aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoclient(v = vs.110)的.aspx [<一个href =https://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoclient(v=vs.110).aspx\"target =_ blanktitle =New Window> ^ ]。



获得(甚至设置)鼠标坐标的另一种方法是: https://msdn.microsoft.com/en-us/library/system.windows.forms .cursor.position%28v = vs.110%29.aspx [ ^ ]。



-SA

Hello all,

Question about X/Y coordinates from windows form.
At the moment i retrieve the right coordinates using the code below.

protected override void OnMouseMove(MouseEventArgs e)
{
        base.OnMouseMove(e);
        MouseMove_X_Horizontal = e.X;
        MouseMove_Y_Vertical = e.Y;
        this.X_Coordinates.Text = e.X.ToString();
        this.Y_Coordinates.Text = e.Y.ToString();
}



Butt when im moving the mouse over a picturebox or text label I dont get any feedback anymore, only when i'm moving it around the form without passing any objects.

Is there a possibilty too retreive the actual coordinates of the mouse even when its moving over a object?

I already tried a couple of things like

Cursor.GetPosition


same result for this option.

Could you guys give me a little push in the right direction?

Thanks in advance

解决方案

You already got these coordinates; they come to you in the MouseEventArgs instance:
https://msdn.microsoft.com/en-us/library/system.windows.forms.mouseeventargs%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.mouseeventargs.location(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.mouseeventargs.x(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.mouseeventargs.y(v=vs.110).aspx[^].

If you want, you can perform coordinate transform from control to screen and visa versa:
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoscreen(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoclient(v=vs.110).aspx[^].

Another way to get (and even set) mouse coordinate is this: https://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position%28v=vs.110%29.aspx[^].

—SA


这篇关于如何获得实时光标坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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