title: How to use ScrollableControl with AutoScroll set to false
body: <p>I have a custom control that zooms on a custom drawn document canvas.</p>
  
  <p>I tried using AutoScroll but it was not giving satisfactory results.  When I would set AutoScrollPosition and AutoScrollMinSize back to back (in any order) it would force a paint and cause jitter each time the zoom changes.  I assume this was because it was calling an Update and not Invalidate when I modified both properties.</p>
  
  <p>I am now manually setting the HorizontalScroll and VerticalScroll properties with <strong>AutoScroll set to false</strong> like so each time the Zoom level or the client size changes:</p>
  
  <pre><code>int canvasWidth = (int)Math.Ceiling(Image.Width * Zoom) + PageMargins.Horizontal;
  int canvasHeight = (int)Math.Ceiling(Image.Height * Zoom) + PageMargins.Vertical;
  
  HorizontalScroll.Maximum = canvasWidth;
  HorizontalScroll.LargeChange = ClientSize.Width;
  
  VerticalScroll.Maximum = canvasHeight;
  VerticalScroll.LargeChange = ClientSize.Height;
  
  if (canvasWidth &gt; ClientSize.Width)
  {
      HorizontalScroll.Visible = true;
  }
  else
  {
      HorizontalScroll.Visible = false;
      HorizontalScroll.Value = 0;
  }
  
  if (canvasHeight &gt; ClientSize.Height)
  {
      VerticalScroll.Visible = true;
  }
  else
  {
      VerticalScroll.Visible = false;
      VerticalScroll.Value = 0;
  }
  
  int focusX = (int)Math.Floor((FocusPoint.X * Zoom) + PageMargins.Left);
  int focusY = (int)Math.Floor((FocusPoint.Y * Zoom) + PageMargins.Top);
  
  focusX = focusX - ClientSize.Width / 2;
  focusY = focusY - ClientSize.Height / 2;
  
  if (focusX &lt; 0)
      focusX = 0;
  if (focusX &gt; canvasWidth - ClientSize.Width)
      focusX = canvasWidth - ClientSize.Width;
  
  if (focusY &lt; 0)
      focusY = 0;
  if (focusY &gt; canvasHeight - ClientSize.Height)
      focusY = canvasHeight - ClientSize.Height;
  
  if (HorizontalScroll.Visible)
      HorizontalScroll.Value = focusX;
  
  if (VerticalScroll.Visible)
      VerticalScroll.Value = focusY;
  </code></pre>
  
  <p>In this case, <strong>FocusPoint</strong> is a PointF structure that holds the coordinates in the bitmap which the user is focused on (for example, when they mouse wheel to zoom in they are focusing on the current mouse location at that time).  This functionality works for the most part.</p>
  
  <p>What does not work is the scroll bars.  If the user tries to manually scroll by clicking on either scroll bar, they both keep returning to 0.  I do not set them anywhere else in my code.  I have tried writing the following in the OnScroll() method:</p>
  
  <pre><code>if (se.ScrollOrientation == ScrollOrientation.VerticalScroll)
  {
      VerticalScroll.Value = se.NewValue;
  }
  else
  {
      HorizontalScroll.Value = se.NewValue;
  }
  
  Invalidate();
  </code></pre>
  
  <p>But this causes some very erratic behavior including flicking and scrolling out of bounds.</p>
  
  <p><strong>How am I supposed to write the code for OnScroll?</strong>  I've tried the base.OnScroll but it didn't do anything while AutoScroll is set to false.</p>