Bilal Tayfur
Bilal Tayfur

Reputation: 19

hit enter to click button VC#

I'm working on a WinForm App in C#, and there is only one button on app's screen, app's need is when user hit to enter, button should work as clicked to it. How can this be possible?

Upvotes: 1

Views: 265

Answers (6)

MutchoUser
MutchoUser

Reputation: 575

you can do it in client side:

<script type="text/javascript">
            function searchKeyPress(sender, eventArgs) {
                var c = eventArgs.get_keyCode();
                if (c == 13) {
                    var btnQiuckSearch = document.getElementById('<%=RbSearch.ClientID%>');
                    btnQiuckSearch.click();
                }
            }
 </script>

Upvotes: 0

Amit
Amit

Reputation: 22076

Form.AcceptButton Property

Gets or sets the button on the form that is clicked when the user presses the ENTER key.

// Set the accept button of the form to button1.
   form1.AcceptButton = button1;// button1 is your required button

Additional information

For cencel you can use

form1.CancelButton = MyCancelButton;

Upvotes: 1

Writwick
Writwick

Reputation: 2163

Use This :

this.AcceptButton = button1 // Say you want to set Enter to button1

Know More about AcceptButton

Upvotes: 2

Raghuveer
Raghuveer

Reputation: 2638

goto form properies Set AcceptButton to your button ID

Upvotes: 2

mgnoonan
mgnoonan

Reputation: 7200

Set the form's AcceptButton property to the button you want executed when the user hits Enter.

Upvotes: 2

KingCronus
KingCronus

Reputation: 4519

Your form has an "AcceptButton" property.

Set it to the button in question and it will behave as you describe.

Please see the documentation here:

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.acceptbutton.aspx

Upvotes: 8

Related Questions