Vb.net 如何不接受文本框中的数字?
我知道如何做上述相反的事情。让它只接受数字,但它接受除此之外的所有内容怎么样 代码我只用于数字Vb.net 如何不接受文本框中的数字?,vb.net,Vb.net,我知道如何做上述相反的事情。让它只接受数字,但它接受除此之外的所有内容怎么样 代码我只用于数字 If Asc(e.KeyChar) <> 8 Then If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then My.Computer.Audio.PlaySystemSound(System.Media.SystemSounds.Asterisk)
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
My.Computer.Audio.PlaySystemSound(System.Media.SystemSounds.Asterisk)
e.Handled = True
End If
End If
End If
如果Asc(e.KeyChar)8那么
如果Asc(e.KeyChar)<48或Asc(e.KeyChar)>57,则
My.Computer.Audio.PlaySystemSound(System.Media.SystemSounds.Asterisk)
e、 已处理=真
如果结束
如果结束
如果结束
是否只需反转条件
If Not (Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57) Then
如果不是(Asc(e.KeyChar)<48或Asc(e.KeyChar)>57),则
是否只需反转条件
If Not (Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57) Then
如果不是(Asc(e.KeyChar)<48或Asc(e.KeyChar)>57),则
试试这个
If Not Char.IsLetter(e.KeyChar) And Not e.KeyChar = Chr(Keys.Delete) And Not e.KeyChar = Chr(Keys.Back) Then
e.Handled = True
End If
试试这个
If Not Char.IsLetter(e.KeyChar) And Not e.KeyChar = Chr(Keys.Delete) And Not e.KeyChar = Chr(Keys.Back) Then
e.Handled = True
End If
您可以使用Char.IsDigit来判断字符是否为十进制数字
If Char.IsDigit(e.KeyChar) Then
My.Computer.Audio.PlaySystemSound(System.Media.SystemSounds.Asterisk)
e.Handled = True
End If
您可以使用Char.IsDigit来判断字符是否为十进制数字
If Char.IsDigit(e.KeyChar) Then
My.Computer.Audio.PlaySystemSound(System.Media.SystemSounds.Asterisk)
e.Handled = True
End If