Search code examples
c#.netcompact-framework

compact framework 2.0 detecting enter key in a textbox


I am developing a small app for a Motorola 9090-G using .net compact framework 2.0.

My problem is that I can't seem to detect an enter keypress in a textbox. How do you detect an enter keypress in a textbox?

None of the 3 detection methods seems to work. Interestingly, it DOES work in the ppc emulator. It does not work on my actual hardware however.

private void tbxQTY_KeyDown(object sender, KeyEventArgs e)
{    
  if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter || e.KeyCode == Keys.Decimal)
  {
    QTYEntered();
    e.Handled = true;
  }

  if (e.KeyData == Keys.Enter || e.KeyData == Keys.Return)
  { do something }


  if (e.KeyValue == (char)13)
  { QTYEntered(); MessageBox.Show("test"); e.Handled = true; }
}

Solution

  • For me the answer was to use the KeyPress event, not KeyDown:

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                // Enter
            }
        }