public partial class Form1 : Form
{
bool bDraging = false;
int x = 0;
int y = 0;
public Form1()
{
InitializeComponent();
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
bDraging = true;
x = e.X;
y = e.Y;
MessageBox.Show("down");
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (!bDraging)
return;
int x1 = e.X - x;
int y1 = e.Y - y;
this.pictureBox1.Location = new Point(pictureBox1.Location.X + x1,
pictureBox1.Location.Y + y1);
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
bDraging = false;
}
}
///
这段代码用着没有问题,但是有个困惑,不知道
移动后不需要写
x = e.X;
y = e.Y;