2015-07-06 50 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 *。 –