主要代码如下:
Point mouse_offset = new Point();
public MyPicture()
{
this.MouseMove += new MouseEventHandler(Common_MouseMove);
this.MouseDown += new MouseEventHandler(Common_MouseDown);
}
private void Common_MouseMove(object sender, MouseEventArgs e)
{
Control control = (Control)sender;
//((Control)sender).Cursor = Cursors.Arrow;
if (e.Button == MouseButtons.Left)
{
//Point mousePos = Control.MousePosition;
//mousePos.Offset(mouse_offset.X, mouse_offset.Y);
//((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
control.Left = control.Left + e.X - mouse_offset.X;
control.Top = control.Top + e.Y - mouse_offset.Y;
}
}
private void Common_MouseDown(object sender, MouseEventArgs e)
{
mouse_offset = new Point(e.X, e.Y);
}
我用的就是这段代码.