title: how to get smartphone like scrolling for a winforms touchscreen app ( scrolling panel )
body: <p>After scouring the articles online I have come up with this design for a winforms based touchscreen app that needs smartphone like scrolling. The app itself will run on a tablet laptop or touchscreen desktop.</p>
  
  <ul>
  <li>I put everything I want to scroll on a panel. </li>
  <li>Set autoscroll to true (which will show scrollbars)</li>
  <li>Now put this whole panel inside a groupbox</li>
  <li>Shrink the groupbox until the scrollbars are hidden (visually hidden, not visible = false)</li>
  </ul>
  
  <p>Now the fun part I am stuck at. I think I have to handle the mousedown, mouseup &amp; mousemove on the panel to set the autoscrollposition so that when someone touches the panel and drags, it does it's scroll magic. Please help fill in the few lines of code in below method stubs. The <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollablecontrol.autoscrollposition.aspx" rel="noreferrer">msdn doc</a> on autoscrollposition is very confusing since it returns negative numbers but needs to be set to positive with abs and what not. </p>
  
  <pre><code>Point mouseDownPoint;
  Point mouseUpPoint;
  Point mouseDragPoint;
   private void myPanel_MouseDown(object sender, MouseEventArgs e)
   {
      this.mouseDownPoint = e.Location;
      Console.WriteLine("Mouse down at {0}", e.location);
   }
  
   private void myPanel_MouseUp(object sender, MouseEventArgs e)
   {
      this.mouseUpPoint = e.Location;
      this.mouseDownPoint = new Point(); //will set for IsEmpty check
      Console.WriteLine("Mouse Up at {0}", e.location);
   }
  
   private void myPanel_MouseMove(object sender, MouseEventArgs e)
   {
      Console.WriteLine("Mouse at {0}", e.location);
      if (mouseDownPoint.IsEmpty()) //finger is off the touchscreen
         return;
      myPanel.Autocrollposition = ??
   }
  </code></pre>
  
  <p>thank you</p>
  
  <p><strong>//UPDATE - Below I have with trial and error working &amp; tested code. (not refactored). If someone has a more elegant solution please post.</strong> </p>
  
  <pre><code>    Point mouseDownPoint;
      private void innerpanel_MouseDown(object sender, MouseEventArgs e)
      {
          if (e.Button == MouseButtons.Left)
              this.mouseDownPoint = e.Location;
      }
  
      private void innerpanel_MouseMove(object sender, MouseEventArgs e)
      {
          if (e.Button != MouseButtons.Left)
              return;
          if ((mouseDownPoint.X == e.Location.X) &amp;&amp; (mouseDownPoint.Y == e.Location.Y))
              return;
  
          Point currAutoS = innerpanel.AutoScrollPosition;
          if (mouseDownPoint.Y &gt; e.Location.Y)
          {
              //finger slide UP
              if (currAutoS.Y != 0)
                  currAutoS.Y = Math.Abs(currAutoS.Y) - 5;
          }
          else if (mouseDownPoint.Y &lt; e.Location.Y)
          {
              //finger slide down
              currAutoS.Y = Math.Abs(currAutoS.Y) + 5;
          }
          else
          {
              currAutoS.Y = Math.Abs(currAutoS.Y);
          }
  
          if (mouseDownPoint.X &gt; e.Location.X)
          {
              //finger slide left
              if (currAutoS.X != 0)
                  currAutoS.X = Math.Abs(currAutoS.X) - 5;
          }
          else if (mouseDownPoint.X &lt; e.Location.X)
          {
              //finger slide right
              currAutoS.X = Math.Abs(currAutoS.X) + 5;
          }
          else
          {
              currAutoS.X = Math.Abs(currAutoS.X);
          }
          innerpanel.AutoScrollPosition = currAutoS;
          mouseDownPoint = e.Location; //IMPORTANT
  
      }
  </code></pre>