title: How can I use padding to move an image inside a picturebox in C#?
body: <p>I am trying to move an image inside a picturebox with the mouse by changing the padding of the picturebox. I am able to move the image, but it <a href="https://imgur.com/iFGSIFc" rel="nofollow noreferrer">moves too much</a>. This is what I got so far:</p>
  
  <pre><code>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;
  }
  </code></pre>