I have a TextBox with WordWrap to false and Multiline to true. I am using it as a text editing box for my application.
I can set the cursor to the end (SelectionStart and SelectionLength). But how do I programmatically make the TextBox to display the content with the last character (cursor) in view when the text is longer than the width of the control
Thanks in advance.

How to make the end of TextBox.Text in view?
WiT8litZ
Have you tried the TextBox.ScrollToCaret method
Tony
G.A. Boonzaaijer
That's what I did. The cursor is at the end of the text alright. But whether the end of text is in view when the TextBox control gets focus is sort of random. Sometimes the tail is shown (meaning the front part of the text is outside the control), most of the time it shows beginning with the first character.
THanks
Lau Han Ching
What event for the TextBox are you placing the SelectionStart and SelectionLength statements in
Is it possible that some other code from some other event is resetting these values Try displaying them during the GotFocus event of the control.
Rob Caron
JJ Kane
Matty, thanks. But still no joy.
I moved the two statements to the GotFocus handler, but when focussed, the text box still shows the first character in view. SelectionStart is at the right position because the moment I pressed a key, the new character is appended to the end of the text (and the end of the text comes into view).
Thomas H. Grohser
Cat Z
Thanks but this is not what I want.
Imagine a spreadsheet and a cell is a TextBox. When I click on it, I want to go into edit mode with the cursor at the end and the end of the text showing, before the user has to press any key.
stephanielauym
One way is increasing the text box width or height to display full text, it can be done by calculateing the width occupied by the text in the text box,
from the text width, modify the text box height or width. following code will use to measure the text width.
Graphics g = textBox1.CreateGraphics();
SizeF txtSize = g.MeasureString( textBox1.Text, textBox1.Font );