keypress to include the back space
-
private sub num_KeyPress (ByVal sender......blah blah....) If e.KeyChar < "0" or e.KeyChar > "9" then e.handled = true end if end sub can someone plz help iam only using the numbers and want to include the backspace button as well...:rolleyes:
-
private sub num_KeyPress (ByVal sender......blah blah....) If e.KeyChar < "0" or e.KeyChar > "9" then e.handled = true end if end sub can someone plz help iam only using the numbers and want to include the backspace button as well...:rolleyes:
Try this:
...
If (e.KeyChar < '0' Or e.KeyChar > '9') And e.KeyChar <> '\b' Then
...Additionally if using .NET 2.0 probably it would be better if you used PreviewKeyDown event:
Private Sub num_PreviewKeyDown(ByVal sender As Object, e As PreviewKeyDownEventArgs)
e.IsInputKey = ((e.KeyCode = Keys.Back) And (e.Modifiers = 0)) Or ((e.KeyCode >= Keys.D0 Or e.KeyCode <= D9 Or e.KeyCode >= Keys.NumPad0 Or e.KeyCode <= Keys.NumPad9) And (e.Modifiers = 0))
End SubThis way you can handle key combinations like Alt + 0, Ctrl + Backspace, etc. If using .NET 1.1 then use KeyDown to set a flag and check the flag value on the KeyPress event to set the Handled property.
- Xint0