C#拖动控件问题
C#怎么让一个button拖动后top,left不要出去panel1,只能在panel1里面。下面的代码怎么修改????程序代码:
private bool isMove = false; private int MouseDownX; private int MouseDownY; private void lblCode_MouseMove(object sender, MouseEventArgs e) { if (isMove)//如果左键按下的话 { ((Button)sender).Location = new Point(((Button)sender).Left + e.X - MouseDownX, ((Button)sender).Top + e.Y - MouseDownY); } private void lblCode_MouseDown(object sender, MouseEventArgs e) { isMove = true; MouseDownX = e.X; MouseDownY = e.Y; } private void lblCode_MouseUp(object sender, MouseEventArgs e) { isMove = false; }
[ 本帖最后由 宇智波曌 于 2012-5-12 15:49 编辑 ]