KeyPressEvent handler

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an event handler for a textBox with the following code inside:

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

This prevents anyone from entering a non-digit into the text box, but it
also prevents then from using the backspace key. I know there is a way
around this but can't find it.
 
cashdeskmac said:
I have an event handler for a textBox with the following code inside:

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

This prevents anyone from entering a non-digit into the text box, but it
also prevents then from using the backspace key. I know there is a way
around this but can't find it.
if(!char.IsControl(e.KeyChar)&&!char.IsDigit(e.KeyChar))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top