vb6.0窗口上有两个文本框,一个有英文字,一个为空,在空的框里输入

2025-04-26 05:12:37
推荐回答(2个)
回答1:

假定有英文字的文本框是Text1,空的文本框是Text2:

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii <> Asc(Mid(Text1.Text, Len(Text2.Text) + 1, 1)) Then KeyAscii = 0
End Sub

回答2:

Dim n As Integer
Private Sub Text2_KeyPress(KeyAscii As Integer)
    n = Len(Text2.Text)
    If n > Len(Text1.Text) Then Exit Sub
     If Mid(Text1.Text, n + 1, 1) <> Chr(KeyAscii) Then KeyAscii = 0
End Sub