//add the handler to the textbox this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress);
private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { MessageBox.Show("Enter pressed"); } }
TextBox tb = new TextBox(); tb.KeyDown += new KeyEventHandler(tb_KeyDown); static void tb_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { //enter key is down } }