4
Contributors
4
Replies
9
Views
6 Years
Discussion Span
Last Post by AngelicOne
0

Do you want it so that if you press enter in your textbox it will click a button for you?

If so you can use the following:

private void txtBox_keyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13) //13 = enter
            {
                button1.PerformClick();
            }
        }

If this is not what you want you should clarify your question.

1

Alternativley, set the forms AcceptButton property to the button you want to execute on Enter.
Setting the forms CancelButton property will do the same thing for Escape.
And setting the forms HelpButton captures the F1 key.

Votes + Comments
i used this. thanks
1

Your can use this code:

  private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            String key = Convert.ToString(e.KeyChar);
            if (key == "r")//    r notifies return key
            {
                btnSearch_Click(null, null);
            }
        }

Edited by Nick Evan: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.