以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]文本框运行事件代码后,使光标在文本最后  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=108065)

--  作者:jyh7081
--  发布时间:2017/10/15 17:42:00
--  [求助]文本框运行事件代码后,使光标在文本最后

我在textbook的TextChanged事件设置了排版代码,怎样在控件文本变动后,光标焦点在文字的最后;

现在的情况是点击回车键,光标到了首行首字符;

 

Dim txt As WinForm.TextBox = e.Form.Controls("TextBox1")
Dim ary() As String = txt.Text.Split(chr(13))
Dim str As String = ""
For Each s As String In ary
    If s <> chr(10) Then
        str &= "    " & s.trim & vbcrlf \'行首空格
        str &= vbcrlf & ""
    End If
Next
txt.text = str


--  作者:有点甜
--  发布时间:2017/10/15 18:05:00
--  
Dim txt As WinForm.TextBox = e.Form.Controls("TextBox1")
If txt.text.EndsWith(chr(10)) = False Then
    Dim ary() As String = txt.Text.Split(chr(13))
    Dim str As String = ""
    For Each s As String In ary
        If s <> chr(10) Then
            str &= "    " & s.trim & vbcrlf \'行首空格
            str &= vbcrlf & ""
        End If
    Next
    systemready = False
    txt.text = str
    txt.SelectionStart = txt.text.Length
    systemready = True
End If