I am inserting this into an event KeyPress:
KeyPress
e.Handled = !Char.IsNumber(e.KeyChar);
But I do not have a key Backspace, how to fix it?
What about:
e.Handled = !(Char.IsNumber(e.KeyChar) || e.KeyChar == 8);
Or equivalently:
e.Handled = !Char.IsNumber(e.KeyChar) && e.KeyChar != 8;
(As in the Roman answer , you can use '\b'instead of 8 in the code above.)
'\b'
here's how to check if backspace has been pressed:
if(e.KeyChar == '\b'){//backspace was pressed}
backspace keye.KeyChar == (char) Keys.Back