将最大长度设置为 12 将其放在 text1 的按键中,它将使用破折号和仅数字来格式化
If Len(Text1.Text) = 3 Or Len(Text1.Text) = 7 Then
Text1.Text = Text1.Text & "-"
Text1.SelStart = Len(Text1.Text)
End If
If KeyAscii <> 127 And KeyAscii <> 8 And KeyAscii <> 13 Then
If IsNumeric(Chr(KeyAscii)) = False Then
KeyAscii = 0
End If
ElseIf KeyAscii = 8 Then
If Right(Text1.Text, 1) = "-" Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
Text1.SelStart = Len(Text1.Text)
End If
End If
如果您只想要数字文本框,请在按键中使用以下内容
If KeyAscii <> 127 And KeyAscii <> 8 And KeyAscii <> 13 Then
If IsNumeric(Chr(KeyAscii)) = False Then
KeyAscii = 0
End If
End If