I have a text box with a displayed string already in it. To bring the cursor to the textbox I am already doing
txtbox.Focus();
But how do I get the cursor at the end of the string in the textbox ?
I have a text box with a displayed string already in it. To bring the cursor to the textbox I am already doing
txtbox.Focus();
But how do I get the cursor at the end of the string in the textbox ?
On
You can set the caret position using TextBox.CaretIndex. If the only thing you need is to set the cursor at the end, you can simply pass the string's length, eg:
txtBox.CaretIndex=txtBox.Text.Length;
You need to set the caret index at the length, not length-1, because this would put the caret before the last character.
For Windows Forms you can control cursor position (and selection) with
txtbox.SelectionStartandtxtbox.SelectionLengthproperties. If you want to set caret to end try this:For WPF see this question.