Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to constantly scroll to the end of text in multiline text box? [duplicate]

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?

like image 777
HelpNeeder Avatar asked Jan 18 '12 20:01

HelpNeeder


People also ask

How do you move the cursor to the end of the text in a TextBox C#?

To position the cursor at the end of the contents of a TextBox control, call the Select method and specify the selection start position equal to the length of the text content, and a selection length of 0.

How do I enable multiline in a text box?

Step 1: Create a windows form. Step 2: Drag the TextBox control from the ToolBox and drop it on the windows form. You can place TextBox anywhere on the windows form according to your need. Step 3: After drag and drop you will go to the properties of the TextBox control to set the Multiline property of the TextBox.

How do you scroll to the bottom in C#?

Document. Body. ScrollIntoView(false); The boolean parameter for ScrollIntoView () is true to align the scrollbar with the top of the document, and false to align the scrollbar with the bottom of the document.


3 Answers

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()
like image 67
Kotch Avatar answered Oct 18 '22 22:10

Kotch


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);
like image 41
HelpNeeder Avatar answered Oct 18 '22 21:10

HelpNeeder


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.

like image 33
John Jeffery Avatar answered Oct 18 '22 23:10

John Jeffery