[英]How to handle textbox selection start property in vb.net or c#
當我將文本分配給文本框時,選擇開始屬性為零,因此光標(插入符號)正在移動到文本框的第一個位置。 如何解決這個問題呢?
代碼示例
考慮到文本框已經有像“Hello Developers”這樣的文本
Dim CurPosition As Integer = TextBox1.SelectionStart
'CurPosition=11 (i.e) SelectionStart is 11 (cursor position)'
TextBox1.Text = TextBox1.Text.Remove(5, 11)
'After Assigning Text the selectionStart is 0 (cursor position)'
TextBox1.SelectionStart = TextBox1.TextLength
'Here After the selectionstart is 5'
TextBox1.ScrollToCaret()
所以當我執行這段代碼時,cursor 會上下移動,所以如何解決這個問題。
我想我真的不知道你的問題是什么。
但我認為您可以在 scrolltocaret() 之后再次分配 selectionstart-property,或者只使用 select() 方法。
您的意思是您的插入符號不會出現在文本框中嗎? 如果是這樣嘗試:
Dim CurPosition As Integer = TextBox1.SelectionStart
'CurPosition=11 (i.e) SelectionStart is 11 (cursor position)'
TextBox1.Text = TextBox1.Text.Remove(5, 11)
'After Assigning Text the selectionStart is 0 (cursor position)'
TextBox1.SelectionStart = TextBox1.TextLength
'Here After the selectionstart is 5'
TextBox1.ScrollToCaret()
TextBox1.Focus()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.