Detecting Numeric keys in WinForms

What is the command to detect if the key that was pressed was numeric (e.g. 0 – 9) on a Windows Form? Or conversely, if the key that was pressed was NOT numeric? In C# the command is something like:

if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)

Parents Reply
  • The command you suggested was giving me an “Invalid conditional expression” error. So I tried it as follows: I moved the key that was pressed into a variable which I named “digit” and I then compared it against that variable as follows:

    if type Char::IsDigit(digit)
          do something

    This works for what I am trying to achieve. Thanks for your help!

No Data