title: Scroll by dragging with mouse
body: <p>I am trying to make a scrollable panel but without the scrollbar and to scroll by dragging with mouse vertically... here is what somebody helped me to do so far.. : </p>
  
  <pre><code> private void panel1_MouseEnter(object sender, EventArgs e)
      {
          panel1.AutoScroll = false;
      }
  
      private int ValidateChange(int change)
      {
          var padding = -1;
          if (change &lt; 0)
          {
              var max = (from Control control in Controls select control.Top + control.Height + padding).Concat(new[] { int.MinValue }).Max();
  
              if (max &lt; Height + Math.Abs(change))
              {
                  return Height - max;
              }
          }
          else
          {
              var min = (from Control control in Controls select control.Top).Concat(new[] { int.MaxValue }).Min();
  
              if (min &gt; padding - Math.Abs(change))
              {
                  return padding - min;
              }
          }
          return change;
      }
  
      private void HandleDelta(int delta)
      {
          var change = ValidateChange(delta);
  
          foreach (Control control in Controls)
          {
              control.Top += change;
          }
  
      }
  
      private void panel1_MouseWheel(object sender, MouseEventArgs e)
      {
          HandleDelta(e.Delta);
          base.OnMouseWheel(e);
      }
  
      private Point _mouseLastPosition;
  
      private void panel1_MouseDown(object sender, MouseEventArgs e)
      {
          if (e.Button == MouseButtons.Left)
          {
              _mouseLastPosition = e.Location;
          }
          base.OnMouseDown(e);
      }
  
      public void panel1_MouseMove(object sender, MouseEventArgs e)
      {            
              if ((MouseButtons &amp; MouseButtons.Left) != 0)
              {
                  var delta = e.Y - _mouseLastPosition.Y;
                  HandleDelta(delta);
                  _mouseLastPosition = e.Location;
              }
              base.OnMouseMove(e);
  
      }
  </code></pre>
  
  <p>but it goes just too fast..
  EDIT: the dragging by mouse looks a little bit weird i dont know why and when I try to use mouse wheel it bugs and gives me this error: An unhandled exception of type 'System.StackOverflowException' occurred in System.Core.dll at this line <code>var max = (from Control control in Controls select control.Top + control.Height + padding).Concat(new[] { int.MinValue }).Max();</code></p>
  
  <p><a href="https://i.stack.imgur.com/R49Ge.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/R49Ge.gif" alt=""></a></p>