How to do this? I read that it is done in event.

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.

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.

commented: 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);
            }
        }

I used the acceptbutton property. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.