设置光标位置 [英] setting cursor position
问题描述
编码员们!
我有一个动态生成的点(x,y),想知道我该如何编写鼠标处理程序函数将此点传递给系统范围的鼠标事件,以将光标位置设置为此点.
生成动态点的函数是:
Hi Coders!
I''ve a dynamically generated points (x,y) and want to know how do I write a mouse handler function to pass this point to system wide mouse event to set the cursor location to this point.
The function that generates dynamic point is:
public void getpoint()
{
......
....
for (int i = 0; i < eyes.Total; i++)
{
CvRect r = eyes[i].Value.Rect;
CvPoint center = new CvPoint
{
X = Cv.Round((r.X + r.Width * 0.45) * Scale),
Y = Cv.Round((r.Y + r.Height * 0.45) * Scale)
};
cursorpos = center;
}
}
cursorpos存储(X,Y)的值及其全局值. taht函数返回的值是
cursorpos stores the value of (X,Y) and its global. The function taht returns this value is
public CvPoint GetCursorPos()
{
return cursorpos;
}
并且我将其称为
and I''m calling it as
private void BtnPowerUrEyes_Click(object sender, EventArgs e)
{
CvPoint newcurpos = pupilobj.GetCursorPos();
int x = newcurpos.X;
int y = newcurpos.Y;
Cursor.Position = new Point(x , y);
}
但是光标位置不会动态变化:(
我知道我必须循环调用GetCorsprPos(),但是如果我这样做,它将挂起:(
But the cursor position is not changing dynamically :(
I know I''ve to call GetCorsprPos() in a loop but if I do that it hangs :(
Thanks for the help in advance!
推荐答案
我认为您可以编写以下代码来设置鼠标的光标位置.
说,
Hi,
I think you can write below code to set cursor position of mouse.
Say,
Cursor.Position = new Point(x, y);
简单,Cursor包含名称空间System.Windows.Forms.
谢谢:)
希望对您有帮助
Simple, Cursor includes name spaces System.Windows.Forms.
Thanks :)
I hope, this will help you
希望 ^ ]可能会为您提供帮助.
Hope this[^] might help you.
这篇关于设置光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!