vb中文本框自动换行

2025-04-07 01:32:27
推荐回答(4个)
回答1:

Private Sub Text1_Change()
If Text1.Tag = "1" Then Exit Sub
Text1.Tag = "1"
Text1.Text = Replace(Text1.Text, "-", "")
If Len(Text1.Text) > 6 Then
Text2.Text = Mid(Text1.Text, 7)
Text1.Text = Left(Text1.Text, 6)
Text2.SelStart = Len(Text2.Text)
Text2.SetFocus
End If
Text1.Tag = ""
End Sub

Private Sub Text2_Change()
If Text2.Tag = "1" Then Exit Sub
Text2.Text = Replace(Text2.Text, "-", "")
If Len(Text2.Text) > 6 Then
Text3.Text = Mid(Text2.Text, 7)
Text2.Text = Left(Text2.Text, 6)
Text3.SelStart = Len(Text3.Text)
Text3.SetFocus
End If
Text2.Tag = ""
End Sub

回答2:

代码如下。
=================
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then Text2.SetFocus
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then Text3.SetFocus
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then Text1.SetFocus
End Sub

回答3:

给text1,text2,text3分别设置索引值一般从0开始,即分别设为0,1,2
Private Sub text1_keypress(keyascii As Integer)
If Text1.Text <> "" And keyascii = 13 Then SendKeys "{tab}"
End Sub
Private Sub text2_keypress(keyascii As Integer)
If Text2.Text <> "" And keyascii = 13 Then SendKeys "{tab}"
End Sub
Private Sub text3_keypress(keyascii As Integer)
If Text3.Text <> "" And keyascii = 13 Then SendKeys "{tab}"
End Sub

回答4:

focus的功能你最好看一下,主要是焦点的问题