I need to add text at the end of th开发者_StackOverflowe cursor's position in VB.NET I tried:
TextBox1.Text = TextBox1.Text.Insert(TextBox1.SelectionStart, "<br>")
It works but the cursor position still moves to the starting position.
Just re-set the SelectionStart
property after assigning the text:
Dim insertText = "<br>"
Dim insertPos As Integer = TextBox1.SelectionStart
TextBox1.Text = TextBox1.Text.Insert(insertPos, insertText)
TextBox1.SelectionStart = insertPos + insertText.Length
Turns out there's a really easy way to do this.
TextBox1.SelectedText = "<br>"
Add this code after your code to move the caret to the end of your textbox value:
TextBox1.SelectionStart = TextBox1.TextLength
精彩评论