问题描述
我有以下问题:我正在用C#编写WinForms应用程序,我想获取屏幕-图片的一部分的坐标",在这种情况下,是这只手的顶部(用红点标记).
I have the following problem:I'm writing a WinForms application with C# and i want to get the Screen - Coordinates of a part of a picture, in this case the top of this hand (marked by the red point).
有人知道我该如何编程吗?
Does anybody know how i can do this programmaticaly?
(坐标死了朋克" =此点的坐标)
("Koordinaten dieses Punktes" = Coordinates of this Point)
令您感到困惑的是,上面的图片仅能说明我的问题.我程序的实际目标是将飞镖游戏的鼠标控制的手移到正确的位置,但是仅通过将MouseLocation设置为固定点是不可能的,因为飞镖手每转一圈都会获得另一个x :y到MouseLocation的距离.所以我需要找到飞镖的位置(箭头).
sry for confusing you, the picture above should only demonstrate my problem. The actual target of my program is to move the mouse-controlled-hand of a dart game to the right position, but it isn't possible by only setting the MouseLocation to a fix Point, because every turn the dart-hand gets another x:y distance to the MouseLocation. So I need to find the Location of the dart (-arrow).
我希望每个人都知道我现在的问题.
I hope that everybody knows what my problem is now.
推荐答案
如果您的窗口最小化,隐藏或不在屏幕上,Control.PointToScreen将无法正常工作.您必须下拉至使用Win32 API的Interop:
Control.PointToScreen won't work correctly if your window is minimized, hidden or off the screen.You'll have to drop down to Interop with Win32 APIs:
因此,请先导入API:
so start by importing the API:
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool GetCursorPos(out Point lpPoint);
并使用它:
Point pts;
GetCursorPos(out pts);
MessageBox.Show(this, pts.ToString());
这篇关于C#如何获取屏幕上特定点的坐标. (不是鼠标定位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!