Shawn Petty

Shawn Petty

  • NA
  • 6
  • 0

Having trouble with Catching Keystrokes

May 31 2007 9:37 AM
Hello,

I'm new to the forum, and fairly new to C# developing, and I'm needing a little assistance.

I have a form that has a series of textboxes. When I get to the last textbox, I want the user to be able to Tab or Enter and have it add the results to my XML file.

KeyPreview for the form is set to true, and below is the current coding I have to try and test the keystrokes:

//this is a textbox field

private void numbrackets_KeyDown(object sender, KeyEventArgs e)
{

if (e.KeyCode == Keys.Enter)

{

this.Close();

MessageBox.Show("Enter Was Pressed");

e.Handled = true;

}

}

However, when I press Enter, I get nothing but the "beep" from the keyboard. Obviously I'm missing something, but for the life of me I can't figure out what. Any help would be great!

Thanks
Shawn


Answers (5)