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); } }
c#拖动控件
最新推荐文章于 2020-11-14 17:06:55 发布