9

I'm updating my text box with text using a timer. Each time timer ticks I'm being redirected to the beginning to the text typed in my multiline text box.

How to do this?

HelpNeeder
  • 6,383
  • 24
  • 91
  • 155

3 Answers3

12

I'd say that when you refresh, you could move the selection cursor to the end, then scroll the textbox 'til it's visible using ScrollToCaret.

That'll be something like

 yourtextbox.SelectionStart = yourtextbox.Text.Length
 yourtextbox.ScrollToCaret()
Kotch
  • 334
  • 1
  • 10
12

This works much better. It's better than Kotch's solution because there is no need constantly updating the position of cursor.

txtDisplay.AppendText(txtDisplay.SelectedText);
HelpNeeder
  • 6,383
  • 24
  • 91
  • 155
  • 1
    Certainly the easiest and most intuitive way to both append text to the text box buffer and keep the latest text addition in view. – Roland May 11 '16 at 10:38
2

Try using the TextBox.Select method:

textBox.Select(textBox.Text.Length, 0);

That will set the cursor to just past the last character in the text box.

John Jeffery
  • 990
  • 5
  • 19