2015-07-06 46 views
-1

基本上我想移动我的鼠标,直到角度匹配。 这是我走到这一步(不工作):for循环直角匹配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); 
    } 
} 

什么是做到这一点的正确方法?

+0

你必须有某种数组或集合的迭代来 – jmc

+0

好了,所以我会做类似:'的for(int i = 0; angleVert = eyeangle; i ++){if(eyeangle

+1

我想你可能想要一个'while'循环,但要小心:如果你的逻辑不好,你会以无限循环结束。你需要确保条件最终肯定是真的,或者你有办法打破循环 – musefan

回答

0

您应该使用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); 
    } 
} 
+1

你必须以某种方式更新'eyeangle'和'angleVert',因为'eyeangle'和'angleVert'看起来像* fields *。 –