我在Text1_Change里边写If Len(Text1.Text) >= 2 Then Text2.SetFocus
但是我如果在text1里输错了,想把第1个文本框里的2个数字选中直接改,光标就跳到第2个文本框里了,没法改.
应该怎么做呢?谢谢!

解决方案 »

  1.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = 13 And Len(Text1) >= 2 Then
            Text2.SetFocus
        End If
    End Sub
      

  2.   

    不要用Change事件,改用KeyUpPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
        If Len(Text1) >= 2 Then Text2.SetFocus
    End Sub
      

  3.   

    Private Sub Text1_Change()
         If Len(Text1.Text) >= 2 Then Text2.SetFocus
    End SubPrivate Sub Text1_GotFocus()
        Text1.SelStart = 0
        Text1.SelLength = Len(Text1)
    End Sub
      

  4.   

    排除退格键或者keycode在数字或字母范围内(判断条件你自己看吧),然后再setfocus,这样就可以修改了
    Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
        If KeyCode <> vbKeyBack And Len(Text1) >= 2 Then Text2.SetFocus
    End Sub
      

  5.   

    不要用Change事件,改用KeyUp Private   Sub   Text1_KeyUp(KeyCode   As   Integer,   Shift   As   Integer) 
            If   Len(Text1)   > =   2   Then   Text2.SetFocus 
    End   Sub 可以的,你试试
      

  6.   

    Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    If Len(Text1.Text) >= 2 Then Text2.SetFocus
    End SubPrivate Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)
    If Len(Text2.Text) = 0 And KeyCode = vbKeyBack Then Text1.SelStart = Len(Text1.Text): Text1.SetFocus
    End Sub
      

  7.   


    Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer) 
        If Len(Text1.Text) > = 2 Then Text2.SetFocus 
    End Sub Private Sub Text1_GotFocus()
        Text1.SelStart = 1
        Text1.SelLength = 2
    End Sub
      

  8.   

    Private   Sub   Text1_KeyUp(KeyCode   As   Integer,   Shift   As   Integer)   
            If   Len(Text1.Text)   >   =   2   Then   Text2.SetFocus   
    End   Sub   Private   Sub   Text1_GotFocus() 
            Text1.SelStart   =   0
            Text1.SelLength   =   2 
    End   Sub