使用控件数组,会不?如果不会,那不用看下面的代码了.
Option Explicit
Private Sub Text1_GotFocus(Index As Integer)
Text1(Index).SelStart = 0
Text1(Index).SelLength = Len(Text1(Index))
End Sub
Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Then
If Index = Text1.Count - 1 Then
Text1(0).SetFocus
Else
Text1(Index + 1).SetFocus
End If
ElseIf KeyCode = vbKeyUp Then
If Index = 0 Then
Text1(Text1.Count - 1).SetFocus
Else
Text1(Index - 1).SetFocus
End If
End If
End Sub