1 private bool canMove = false;
2 private Point mousePos;
3
4 private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
5 {
6 if (this.canMove)
7 {
8 pictureBox1.Location = new Point(pictureBox1.Location.X
9 - mousePos.X + e.X, pictureBox1.Location.Y
10 - mousePos.Y + e.Y);
11 }
12 }
13
14 private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
15 {
16 this.canMove = true;
17 this.mousePos = new Point(e.X, e.Y);
18 }
19
20 private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
21 {
22 this.canMove = false;
23 }
//form 的属性AllowDrop改为true