R
roidy
I have a text box and I need to limit the input to just numbers, backspace
and the minus(subtract) key. I`ve set up a KeyPress event for the text box
and am using the following code:-
Private Sub textbox_KeyPress(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles textbox.KeyPress
If Not Char.IsNumber(e.KeyChar) And _
Not e.KeyChar = Chr(Keys.Back) And _
Not e.KeyChar = Chr(Keys.Subtract) Then
e.Handled = True
End If
End Sub
This works perfectly for the number keys and the backspace key but not for
the minus(subtract) key. I can replace Keys.Subtract for any other key on
the keyboard and it works but I can`t get Keys.Subtract to work. Any ideas?
Thanks
Rob
and the minus(subtract) key. I`ve set up a KeyPress event for the text box
and am using the following code:-
Private Sub textbox_KeyPress(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles textbox.KeyPress
If Not Char.IsNumber(e.KeyChar) And _
Not e.KeyChar = Chr(Keys.Back) And _
Not e.KeyChar = Chr(Keys.Subtract) Then
e.Handled = True
End If
End Sub
This works perfectly for the number keys and the backspace key but not for
the minus(subtract) key. I can replace Keys.Subtract for any other key on
the keyboard and it works but I can`t get Keys.Subtract to work. Any ideas?
Thanks
Rob