locked
Error when a letter in a text box RRS feed

  • Question

  • i wanna get an output "Error" in a textBlock when the user enters a letter in a TextBox ?!! 

    Emam

    Thursday, December 12, 2013 5:51 PM

Answers

  • please look at the following code. I added a keydown event to my textbox.

            private void TextBox_KeyDown(object sender, KeyRoutedEventArgs e)
            {
                int asciiCode = Convert.ToInt32(e.Key);
                if ((asciiCode >= 48 && asciiCode <= 57))
                {
                }
                else
                {
                    MessageDialog m = new MessageDialog("Not allowed!");
                    m.ShowAsync();
                    e.Handled = true;
                }
            }

    Thursday, December 12, 2013 7:40 PM