VB 文本框限制
PrivateSubText2_KeyPress(KeyAsciiAsInteger)ki$=Chr(KeyAscii)SelectCaseIndexCase0'只允许输...
Private Sub Text2_KeyPress(KeyAscii As Integer)
ki$ = Chr(KeyAscii)
Select Case Index
Case 0 '只允许输入数字
KeyAscii = IIf(ki Like "#", KeyAscii, 0)
End Select
MsgBox "只能输入数字"
End Sub
加上这段代码后我的文本框确实只能输入数字了,但是不能向里面粘贴,该怎么办?
CRTL+V的时候就提示 "只能输入数字" ,我该怎么办
FLY549583003 这段代码不管用啊,连字母都能输进去了 展开
ki$ = Chr(KeyAscii)
Select Case Index
Case 0 '只允许输入数字
KeyAscii = IIf(ki Like "#", KeyAscii, 0)
End Select
MsgBox "只能输入数字"
End Sub
加上这段代码后我的文本框确实只能输入数字了,但是不能向里面粘贴,该怎么办?
CRTL+V的时候就提示 "只能输入数字" ,我该怎么办
FLY549583003 这段代码不管用啊,连字母都能输进去了 展开
2个回答
展开全部
Private KEB As Boolean
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Me.Caption = KeyCode
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = 2 And KeyCode = 86 Then
Dim temp As String, te As Integer
temp = Clipboard.GetText
If Len(temp) > 0 Then
For i = 1 To Len(temp)
te = Asc(Mid(temp, i, 1))
If te > 47 And te < 60 Then
Else
KEB = True
MsgBox temp
Exit For
End If
Next
End If
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KEB = True Then Exit Sub
Select Case KeyAscii
Case 48 To 59
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
KEB = False
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Me.Caption = KeyCode
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = 2 And KeyCode = 86 Then
Dim temp As String, te As Integer
temp = Clipboard.GetText
If Len(temp) > 0 Then
For i = 1 To Len(temp)
te = Asc(Mid(temp, i, 1))
If te > 47 And te < 60 Then
Else
KEB = True
MsgBox temp
Exit For
End If
Next
End If
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KEB = True Then Exit Sub
Select Case KeyAscii
Case 48 To 59
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
KEB = False
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询