我在 Visual Basic 中有一个文本框(Visual Studio 2010,.net frame work 4.0)
现在我有一个问题!
我希望该用户只输入整数、浮点数、退格键和值范围?
使困惑?
哦,是的,我希望该用户只输入 0-4 之间的值(值可能是十进制的 3.49)
现在我想要完整的代码:
我有这个:
这是工作,但我无法指定 0-4 之间的范围
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) 处理 TextBox1.KeyPress
Dim FullStop As Char FullStop = "." ' if the '.' key was pressed see if there already is a '.' in the string ' if so, dont handle the keypress If e.KeyChar = FullStop And TextBox1.Text.IndexOf(FullStop) <> -1 Then e.Handled = True Return End If ' If the key aint a digit If Not Char.IsDigit(e.KeyChar) Then ' verify whether special keys were pressed ' (i.e. all allowed non digit keys - in this example ' only space and the '.' are validated) If (e.KeyChar <> FullStop) And (e.KeyChar <> Convert.ToChar(Keys.Back)) Then ' if its a non-allowed key, dont handle the keypress e.Handled = True Return End If End If End Sub
如果有人给我完整的代码,我会很高兴
提前谢谢