我需要让文本框只接受Numbers Decimals和Backspace。这是我到目前为止所做的,它适用于数字和退格,但我不知道该怎么做。所以任何帮助都会很棒。
Private Sub txtlength_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtlength.KeyPress
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
答案 0 :(得分:1)
e.Handled = Not (Char.IsDigit(e.KeyChar) Or e.KeyChar = ControlChars.Back Or e.KeyChar = ".")