Failed to capture Enter Key

I have a simple form by which I take input:

12 buttons, 1 text box (disabled and read-only)

enter image description here

this is what i do for input input

Login_KeyDown () is a common method. I call for all KeyDown each component of the user interface and the form itself.

private void Login_KeyDown(object sender, KeyEventArgs e)
{            
  if (e.KeyCode == Keys.Escape)
  {
    Application.Exit();
  }
  else if (e.KeyCode == Keys.NumPad9 || e.KeyCode == Keys.D9)
  {
    button3.BackgroundImage = Properties.Resources.button_hover;
    button3.ForeColor = Color.White;
    pin.Text = pin.Text + "9";
  }
  else if (e.KeyCode == Keys.Back)
  {
    button11.BackgroundImage = Properties.Resources.button_hover;
    button11.ForeColor = Color.White;
    if (pin.Text.Length > 0)
      pin.Text = pin.Text.Substring(0, pin.Text.Length - 1);
  }
  else if (e.KeyCode == Keys.Enter)
  {
    MessageBox.Show(pin.Text);
  }
}

This code works fine when starting the application, but after I clicked on a component, the rest of the code works fine, but the "Enter Key Condition" does not work.

I assume that the "Enter Key Condition" does not work for user interface components or something like that.

" , KeyPressEventArgs, KeyChar == 13, .

, ?

p.s. , 100% KBoard.

+3
2

PreviewKeyDown. .

    private void Form1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
    {
        if (e.KeyCode == Keys.Return)
            MessageBox.Show("I found return");

    }

, , KeyDown, :

    private void Form1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
    {
        if (e.KeyCode == Keys.Return)
            e.IsInputKey = true;
    }

: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.previewkeydown.aspx

+2

Keys.Return

: . ?

0

All Articles