for 循环直到角度匹配 C#

for loop till angls match C#

基本上我想移动我的鼠标直到角度匹配。 这是我到目前为止得到的(不起作用):

for (eyeangle != angleVert)
{
    if (eyeangle < angleVert)
    {
        this.Cursor = new Cursor(Cursor.Current.Handle);
        Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y - 10);
    }

    if (eyeangle > angleVert)
    {
        this.Cursor = new Cursor(Cursor.Current.Handle);
        Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y + 10);
    }
}

正确的做法是什么?

您应该使用 while 而不是 for

while (eyeangle != angleVert)
{
    if (eyeangle < angleVert)
    {
        this.Cursor = new Cursor(Cursor.Current.Handle);
        Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y - 10);
    }

    if (eyeangle > angleVert)
    {
        this.Cursor = new Cursor(Cursor.Current.Handle);
        Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y + 10);
    }
}