2012-07-27 56 views
1

在我的第一個表單(form1)中。我使用mouseToStart()函數使鼠標指針從特定位置開始。將鼠標指針設置爲另一種形式的位置

private void mouseToStart() 
{ 
    Point startingPoint = panel1.Location; 
    startingPoint.Offset(155, 376); 
    Cursor.Position = PointToScreen(startingPoint); 
} 

然後我啓動第二個表單(form2)。當在form2中單擊一個按鈕時,我希望它關閉,鼠標將返回到form1中mouseToStart()函數指定的位置。然而,這並未發生。鼠標停留在我點擊form2的地方,form2關閉。

+0

是否將form2作爲模態窗體打開? – 2012-07-27 04:09:47

+1

那麼,如果問題出在form2上的按鈕代碼中,那就是我們需要看到的代碼。你在設置'Cursor.Position'之前調用'Close()'嗎? – 2012-07-27 04:15:39

回答

1
Form1 myForm1; // Set it to your instance of Form1 
Point startingPoint = myForm1.panel1.Location; // You have to make panel1 public 
startingPoint.Offset(155, 376); 
Cursor.Position = myForm1.PointToScreen(startingPoint);