在TEXT文本框中只允許輸入數字和小數點,如何實現?只能編程實現嗎?
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (Chr(KeyAscii) > "9" Or Chr(KeyAscii) < "0") And Chr(KeyAscii) <> "." Then
KeyAscii = 0
End If
End Sub
回復人:y1g1y1(袁飛☆曾經滄海難為水,除卻VB不是云☆)
在keypress中進行判斷,如果不合格就sendkeys(vb_backspace)
具體函數的參數我不太會寫了,就是用sendkeys的
回復人:playyuer(女㊣愛) (2001-5-8 13:09:00) 得0分
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Asc("-") '允許負數
If Text1.SelStart = 0 Then
If Left(Text1.Text, 1) = "-" Then
KeyAscii = 0
Beep
End If
Else
KeyAscii = 0
Beep
End If
Case 8
'無變化,退格鍵不屏蔽
Case Asc(" ") '32
If Text1.SelLength = 0 Then
KeyAscii = 0
End If
Case Asc(".") '46 '允許小數點
If InStr(Text1.Text, ".") Then
KeyAscii = 0
End If
Case Is < Asc(0) '48
KeyAscii = 0
Case Is > Asc(9) '57
KeyAscii = 0
End Select
End Sub
回復人:liu_feng_fly(一只菜鳥,忽忽悠悠的就飛來了??!)