|
bool isMouseDown = false;
Point mouseOffset;
private void label1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}
private void label1_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
this.Location = mousePos;
}
}
private void label1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOffset = new Point(-e.X, -e.Y);
isMouseDown = true;
}
}
我想实现一个Label的拖动,但是一拖动鼠标就跑到Form的0,0坐标上了,怎么回事啊。
还有 除了这样 还能怎么实现控件的拖动呢? |
|