你这样做法会有很多弊端,我假设你是在特殊状态下使用Dim intRowCount As Integer Dim strTemp As String Dim strRTB As StringPrivate Sub Form_Load() Dim i As Integer
For i = 0 To Text1.UBound Text1(i).MaxLength = 1 Next i
End SubPrivate Sub Text1_Change(Index As Integer) Dim i As Integer If Len(Text1(Index).Text) = Text1(Index).MaxLength Then If Len(strTemp) >= Index + 1 Then Mid(strTemp, Index + 1, 1) = Text1(Index).Text Else strTemp = strTemp & Text1(Index).Text End If If Index = Text1.UBound Then For i = 0 To Text1.UBound Text1(i).Text = "" Next i strRTB = strRTB & strTemp & Chr(13) strTemp = "" intRowCount = intRowCount + 1 Text1(0).SetFocus Else Text1(Index + 1).SetFocus End If
RichTextBox1.Text = strRTB & strTemp End If End Sub
我用3个text测试abc def ghi jkl mn
Private Sub Text1_GotFocus(Index As Integer) Text1(Index).SelStart = 0 Text1(Index).SelLength = 1 End SubPrivate Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer) RichTextBox1.Text = RichTextBox1.Text & Chr(KeyAscii) RichTextBox1.Refresh
If Index = Text1.UBound Then RichTextBox1.Text = RichTextBox1.Text & vbCrLf Text1(0).SetFocus Else Text1(Index + 1).SetFocus End If End Sub
[email protected]
Dim strTemp As String
Dim strRTB As StringPrivate Sub Form_Load()
Dim i As Integer
For i = 0 To Text1.UBound
Text1(i).MaxLength = 1
Next i
End SubPrivate Sub Text1_Change(Index As Integer)
Dim i As Integer If Len(Text1(Index).Text) = Text1(Index).MaxLength Then
If Len(strTemp) >= Index + 1 Then
Mid(strTemp, Index + 1, 1) = Text1(Index).Text
Else
strTemp = strTemp & Text1(Index).Text
End If If Index = Text1.UBound Then
For i = 0 To Text1.UBound
Text1(i).Text = ""
Next i strRTB = strRTB & strTemp & Chr(13)
strTemp = ""
intRowCount = intRowCount + 1
Text1(0).SetFocus
Else
Text1(Index + 1).SetFocus
End If
RichTextBox1.Text = strRTB & strTemp
End If
End Sub
def
ghi
jkl
mn
Private Sub Text1_GotFocus(Index As Integer)
Text1(Index).SelStart = 0
Text1(Index).SelLength = 1
End SubPrivate Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
RichTextBox1.Text = RichTextBox1.Text & Chr(KeyAscii)
RichTextBox1.Refresh
If Index = Text1.UBound Then
RichTextBox1.Text = RichTextBox1.Text & vbCrLf
Text1(0).SetFocus
Else
Text1(Index + 1).SetFocus
End If
End Sub
Text1(Index).SelLength = 1
还有这个功效