Jump to content
  • Advertisement
Sign in to follow this  
phil05

c#: Hitting 'enter' in a text box instead of clicking a button?

This topic is 5461 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
I only know VB.NET [wink]
    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.

Share this post


Link to post
Share on other sites
*translates* ;)


private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == System.Windows.Forms.Keys.Enter)
{
myButton_Click(sender, e);
}
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!