tags:

views:

92

answers:

2

hi

I insert this on KeyPress event:

e.Handled = !Char.IsNumber(e.KeyChar);

but i dont have the BackSpace key, how to fix it ?

thank's

+5  A: 

How about:

e.Handled = !(Char.IsNumber(e.KeyChar) || e.KeyChar == 8);

Or equivalently:

e.Handled = !Char.IsNumber(e.KeyChar) && e.KeyChar != 8;

(As in rm's answer, you can use '\b' instead of 8 in the above code too.)

Jon Skeet
+3  A: 

here's how to check if backspace was pressed:

if(e.KeyChar == '\b'){//backspace was pressed}
roman m
+1 for using the escape sequence for backspace. Wish I'd thought of that :)
Jon Skeet
do i get a badge for being upvoted by Jon Skeet?
roman m
The warm glow should be enough, and given the 4% accept rate, don't expect much else.
pavium