Reputation: 19
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
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
Reputation: 22076
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
Reputation: 2163
Use This :
this.AcceptButton = button1 // Say you want to set Enter to button1
Upvotes: 2
Reputation: 7200
Set the form's AcceptButton
property to the button you want executed when the user hits Enter.
Upvotes: 2
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