title: Maintain TextBox scroll position while adding line
body: <p>In my WinForm application I have a multiline TextBox control (uiResults) which is used for reporting progress while processing a large number of items. Using AppendText works great for automatically scrolling to the bottom at every update, but if the user scrolls back to read some older data I need to turn off the autoscroll. I would rather stay away from P/Invoke calls if possible.</p>
  
  <p>Is it possible to detect if the user has scrolled back without using P/Invoke? For now, I just check SelectionStart which works but requires the user to move the caret from the end of the textbox to stop the autoscroll:</p>
  
  <pre><code>if(uiResults.SelectionStart == uiResults.Text.Length)
  {
    uiResults.AppendText(result + Environment.NewLine);
  }
  </code></pre>
  
  <p>My main problem is that when appending a string using the Text property, the textbox is scrolled to the beginning. I tried to solve this by storing the caret position and resetting and scrolling to it after the update, but this causes the current line to move to the bottom (of course, since ScrollToCaret scrolls no more than the necessary distance to bring the caret into view).</p>
  
  <pre><code>[Continued from above]
  else
  {
    int pos = uiResults.SelectionStart;
    int len = uiResults.SelectionLength;
    uiResults.Text += result + Environment.NewLine;
    uiResults.SelectionStart = pos;
    uiResults.SelectionLength = len;
    uiResults.ScrollToCaret();
  }
  </code></pre>