作者ljuyentintho (小劉)
看板C_Sharp
標題[問題]想讓BUTTON隨著滑鼠的位置而改變
時間Tue Nov 18 21:59:03 2014
我希望讓BUTTON2在過了特定的區域(例如:Ycoordinate <= 180)
的時候可以讓BUTTON2的位置移到目前滑鼠的位置(例如滑鼠的位置是(100,180))
程式碼如下:
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (Ycoordinate <= 180)
{
Point startingPoint1 = Cursor.Position;
startingPoint1.Offset(Cursor.Position.X, Cursor.Position.Y);
IsPainting = false;
Cursor.Position = (startingPoint1);
button2.Location = PointToScreen(startingPoint1);
button2.Visible = true;
}
}
為什麼這樣子跑不出我要的結果呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.114.54.99
※ 文章網址: http://www.ptt.cc/bbs/C_Sharp/M.1416319145.A.307.html
推 Peruheru: 我沒試,純猜測 原因是因為按鈕一移動,你的游標就變成 11/19 08:38
→ Peruheru: 停留在button上,而不是他的容器上,所以事件失效 11/19 08:39
→ Peruheru: 小時候用vb5時我也曾想做出一樣的事 11/19 08:40
→ Peruheru: 不過那時我發現不能這樣寫以後我就放棄了沒找解決方法XD 11/19 08:40