title: Set autoscroll position on mouse move
body: <p>I need to update scroll bar position when I click on image and move picturebox. It is always at the beggining, it only moving on the right side (horizontall) and down (vertical).</p>
  
  <pre><code>    private void pictureBox1_MouseMove_1(object sender, MouseEventArgs e)
      {
  
              ....
  
              Point currentMousePos = e.Location;
              int distanceX = currentMousePos.X - mouseX;
              int distanceY = currentMousePos.Y - mouseY;
              int newX = pictureBox1.Location.X + distanceX;
              int newY = pictureBox1.Location.Y + distanceY;
  
              if (newX + pictureBox1.Image.Width + 10 &lt; pictureBox1.Image.Width &amp;&amp; pictureBox1.Image.Width + newX + 10 &gt; panel1.Width)
              {
                  pictureBox1.Location = new Point(newX, pictureBox1.Location.Y);
              }
              if (newY + pictureBox1.Image.Height + 10 &lt; pictureBox1.Image.Height &amp;&amp; pictureBox1.Image.Height + newY + 10 &gt; panel1.Height)
              {
                  pictureBox1.Location = new Point(pictureBox1.Location.X, newY);
              }
      }
  </code></pre>