I am trying to add a "KeyPress" event to a text box (WinForm)
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckKeys);
and here inside the "CheckKeys":
private void CheckKeys(object sender, System.Windows.Forms.KeyPressEventArgs e) { if (e.KeyChar == (char)13) {
The idea here is that after the text field is in focus and the 'Enter' button is pressed, something will happen ...
However, my car cannot find the KeyPress event. Is there something wrong with my codes?
UPDATE:
I also tried putting KeyDown instead of KeyPress:
private void textBox1_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == Key.Return)
Still not working though ...
c # winforms keyboard-events textbox
abramlimpin
source share