📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "限制文本框的输入"
ClientHeight = 2100
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 2100
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
Height = 375
Left = 720
TabIndex = 0
Top = 720
Width = 3135
End
Begin VB.Label Label1
Caption = "下面的文本框只能输入0123456789/-"
Height = 180
Left = 600
TabIndex = 1
Top = 240
Width = 3240
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Function ValiText(KeyIn As Integer, ValidateString As String, Editable As Boolean) As Integer
Dim ValidateList As String
Dim KeyOut As Integer
If Editable = True Then
ValidateList = UCase(ValidateString) & Chr(8)
Else
ValidateList = UCase(ValidateString)
End If
If InStr(1, ValidateList, UCase(Chr(KeyIn)), 1) > 0 Then
KeyOut = KeyIn
Else
KeyOut = 0
Beep
End If
ValiText = KeyOut
End Function
Private Sub Text1_KeyPress(KeyAscii As Integer)
'第二个参数为限制字符"0123456789/-"。
'第三个参数决定能否使用 [Backspace] 键。
KeyAscii = ValiText(KeyAscii, "0123456789/-", True)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -