日期:2014-05-17 浏览次数:20891 次
private bool isDragging = false; //拖中
private int currentX = 0, currentY = 0; //原来鼠标X,Y坐标
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
isDragging = true; //可以拖动
currentX = e.X;
currentY = e.Y;
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
isDragging = false;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (isDragging)
{
pictureBox1.Top = pictureBox1.Top + (e.Y - currentY);
pictureBox1.Left = pictureBox1.Left + (e.X - currentX);
}
}