【发布时间】:2015-12-30 17:06:10
【问题描述】:
我在 Windows 窗体中有一个设置为多行的文本框。我有一个KeyDown 事件处理程序,它识别文本框中的 Enter 键并执行某些操作,然后从文本框中清除文本。如何以编程方式将插入符号移动到文本框的开头?当我在文本框中按 Ctrl + Home 时,我可以看到它。
我使用SelectionStart 属性尝试了以下操作,但它将光标留在了第二行的开头。
Private Sub txtComments_KeyDown(sender As Object, e As KeyEventArgs) Handles txtComments.KeyDown
If e.KeyCode = Keys.Enter Then
If txtComments.TextLength > 0 Then
AddSelection(txtComments.Text)
txtComments.Clear()
End If
If txtComments.TextLength = 0 Then
txtComments.Focus()
txtComments.SelectionStart = 0
End If
End If
End Sub
【问题讨论】: