Only numbers in Textbox in C# (with Num Lock, WPF Project)

Asked

Viewed 44 times

0

In this command below only the numbers between the quotes (") and the minus (-) of the keyboard work when the user type in a Textbox. I need it to work as well when Num Lock is enabled on the keyboard... This command below does not allow this with Num Lock enabled.

private void Somente_IntCodigo(object sender, KeyEventArgs e)
        {

            KeyConverter key = new KeyConverter();

            if (e.Key == Key.Tab) return;
            if ((char.IsNumber((string)key.ConvertTo(e.Key, typeof(string)), 0) == false))
            {
                e.Handled = true;
            }



        }
  • You know the Keys of the accents, @, keys, brackets, Alt Grs, ? , ! , mathematical signs, etc?

  • I found...https://msdn.microsoft.com/pt-br/library/system.windows.forms.keys%28v=vs.110%29.aspx

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.