title: How to move a pictureBox inside a Panel by Mouse
body: <p>How to move a pictureBox inside a Panel by Mouse.
  Visual Studio 2015 C# Winsows Forms Application.</p>
  
  <p>I've made a primitive slider to control the volume of my WindowsMediaPlayer.
  A panel as the background and a pictureBox inside as the slider-knopf.
  And it works well.
  But purely visually it does not work that good.</p>
  
  <p>I'v searched all around, but can't I find an answer to this little funny problem.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    int posY;
  
      private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
      {
          if (e.Button == MouseButtons.Left)
          {
              posY = e.Y; ;
          }
      }
  
      private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
      {
          PictureBox box = sender as PictureBox;
  
          if (e.Button == MouseButtons.Left)
          {
              box.Top += e.Y - posY;
          }
  
          if (box.Top &lt; 0)
          {
              box.Top = 0;
          }
  
          if (box.Top &gt; 100)
          {
              box.Top = 100;
          }
          int n = box.Top;
          n = n * - 1 + 100;
          label1.Text = n.ToString();
      }
  </code></pre>
  
  <p>When I move the pictureBox out of the edge of the little panel, the pictureBox somehow 'shrinks' in the panel.
  But when I release the mouse, the pictureBox restore its size.</p>
  
  <p><a href="https://i.stack.imgur.com/BMksg.gif" rel="nofollow noreferrer">Slider.gif</a></p>
  
  <p>Why is that.?
  And how can I avoid it.?</p>
  
  <p>Thanks.</p>