如何移动textbox里面字符串光标的位置?

解决方案 »

  1.   

    Private Sub Command1_Click()
        On Error Resume Next
        Text1.SetFocus
        Dim i As Long
        SendKeys "{HOME}"
        For i = 1 To 2 '移到第2个字符处
            SendKeys "{RIGHT}"
        Next
    End Sub
      

  2.   

    可以设置SelStart属性来移动到指定的位置,类似:Private Sub Command1_Click()
        
        Text1.SelStart=0  '移动到最前
        Text1.SelStart=Int(Len(Text1.Text) / 2 )  '移动到中间
        Text1.SelStart=Int(Len(Text1.Text))  '移动到最后End Sub
      

  3.   

    SendKeys "^{HOME}" 到首字符
        SendKeys "{LEFT n}"左移n个字符
        SendKeys "{RIGHT n}" 右移n个字符
        SendKeys "{UP n}" 上移n行
        SendKeys "{DOWN n}" 下移n行
        SendKeys "^{END}" 到末尾
      

  4.   

    SendKeys "^%{left}" '左移一个单词
    SendKeys "^%{right}" '右移一个单词
      

  5.   

    SendKeys "{pgdn}" '向下翻一页
    SendKeys "{pgup}" '向上翻一页
    SendKeys "{End}"  '移至行尾
    SendKeys "{home}"  '移至行首
    SendKeys "^%{left}" '左移一个单词
    SendKeys "^%{right}" '右移一个单词
    SendKeys "^{HOME}" '到首字符
    SendKeys "{LEFT n}"'左移n个字符
    SendKeys "{RIGHT n}" '右移n个字符
    SendKeys "{UP n}" '上移n行
    SendKeys "{DOWN n}" '下移n行
    SendKeys "^{END}" '到末尾