0
我正在嘗試通過更改圖片框的填充使用鼠標在圖片框內移動圖片。我能夠移動圖像,但它moves too much。這是我走到這一步:如何使用填充在C#中的圖片框內移動圖像?
private bool mouseDown;
private Point lastLocation;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseDown = true;
lastLocation = e.Location;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (mouseDown == true)
{
int dx = e.X - lastLocation.X;
int dy = e.Y - lastLocation.Y;
pictureBox1.Padding = new Padding(pictureBox1.Padding.Left + dx,
pictureBox1.Padding.Top + dy, 0, 0);
pictureBox1.Invalidate();
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
mouseDown = false;
}
謝謝。但是,現在它在我第一次移動它時正確移動,但是在移動之前圖像第二次跳回到之前的位置。 – Xrio