How to trigger event when user press Enter key in textbox?
-
which of events to use, and if none of them is actually one for this purpose I though of using KeyPress, but not sure how to make expresion that check if key is Enter (and then execute some method)???
-
which of events to use, and if none of them is actually one for this purpose I though of using KeyPress, but not sure how to make expresion that check if key is Enter (and then execute some method)???
-
which of events to use, and if none of them is actually one for this purpose I though of using KeyPress, but not sure how to make expresion that check if key is Enter (and then execute some method)???
Here is my sample, but for KeyDown event:
private void textBox1_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Enter: DoSomeStuff(); e.SuppressKeyPress = true; return; case Keys.Escape: DoSomeStuff(); e.SuppressKeyPress = true; e.Handled = true; return; case Keys.Space: DoSomeStuff(); e.SuppressKeyPress = true; e.Handled = true; return; case Keys.B: DoSomeStuff(); e.SuppressKeyPress = true; e.Handled = true; return; } }
-
Here is my sample, but for KeyDown event:
private void textBox1_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Enter: DoSomeStuff(); e.SuppressKeyPress = true; return; case Keys.Escape: DoSomeStuff(); e.SuppressKeyPress = true; e.Handled = true; return; case Keys.Space: DoSomeStuff(); e.SuppressKeyPress = true; e.Handled = true; return; case Keys.B: DoSomeStuff(); e.SuppressKeyPress = true; e.Handled = true; return; } }
-
which of events to use, and if none of them is actually one for this purpose I though of using KeyPress, but not sure how to make expresion that check if key is Enter (and then execute some method)???
I think you need KeyDown or KeyUp. add the event handler where you can do:
if(e.KeyCode == KeyCode.Enter){ //Do something }
it should be something like this... Hope this helps.V. If I don't see you in this world, I'll see you in the next one... And don't be late. (Jimi Hendrix)
-
I think you need KeyDown or KeyUp. add the event handler where you can do:
if(e.KeyCode == KeyCode.Enter){ //Do something }
it should be something like this... Hope this helps.V. If I don't see you in this world, I'll see you in the next one... And don't be late. (Jimi Hendrix)
Thanks I think it'll work, I wanted to do same thing but didn't know exact syntax...