【转】禁止vb文本框粘贴输入负数以及输入多个小数点
Dim pd As Boolean
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 46 And KeyAscii <> 8 Then
KeyAscii = 0
End If
If pd = True And KeyAscii = 46 Then
KeyAscii = 0
End If
If pd = False And KeyAscii = 46 Then
pd = True
KeyAscii = 46
End If
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
'防止Ctrl + V 粘贴
If KeyCode = vbKeyV And Shift = vbCtrlMask Then
Text1.Enabled = False
Clipboard.Clear
Text1.Enabled = True
End If
'防止Shift Insert粘贴
If KeyCode = 45 And Shift = vbShiftMask Then
Text1.Enabled = False
Clipboard.Clear
Text1.Enabled = True
End If
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
Text1.Enabled = False
Clipboard.Clear
Text1.Enabled = True
End If
End Sub
posted on 2008-05-03 19:05 LeeXiaoLiang 阅读(939) 评论(2) 编辑 收藏 举报