作者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://webptt.com/cn.aspx?n=bbs/C_Sharp/M.1416319145.A.307.html
1F:推 Peruheru: 我没试,纯猜测 原因是因为按钮一移动,你的游标就变成 11/19 08:38
2F:→ Peruheru: 停留在button上,而不是他的容器上,所以事件失效 11/19 08:39
3F:→ Peruheru: 小时候用vb5时我也曾想做出一样的事 11/19 08:40
4F:→ Peruheru: 不过那时我发现不能这样写以後我就放弃了没找解决方法XD 11/19 08:40