c#: Hitting 'enter' in a text box instead of clicking a button?
I always wondered how to do this for each language. Right now whenever I hit enter in a text box, I get a beep sound. The idea is to allow the user to easly press 'enter' instead of clicking on the submit button every time. What I need is something similar to this pseudocode:
if User presses enter in a text box
do some action.
Thanks.
I only know VB.NET [wink]
That passes the event along to cmdSearch_Click. ASCII 13 is the enter key.
Private Sub txtSearchString_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSearchString.KeyPress If (Asc(e.KeyChar)) = 13 Then cmdSearch_Click(sender, e) End Sub
That passes the event along to cmdSearch_Click. ASCII 13 is the enter key.
*translates* ;)
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if(e.KeyCode == System.Windows.Forms.Keys.Enter) { myButton_Click(sender, e); } }
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement