简体   繁体   English

点击Enter以单击按钮VC#

[英]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. 我正在使用C#开发WinForm应用程序,并且应用程序屏幕上只有一个按钮,应用程序需要在用户点击进入时使用,单击该按钮即可使用。 How can this be possible? 这怎么可能?

Your form has an "AcceptButton" property. 您的表单具有“ AcceptButton”属性。

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 http://msdn.microsoft.com/zh-CN/library/system.windows.forms.form.acceptbutton.aspx

将表单的AcceptButton属性设置为用户单击Enter时要执行的按钮。

转到表单AcceptButtonAcceptButton设置为您的按钮ID

Use This : 用这个 :

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

Know More about AcceptButton 进一步了解AcceptButton

Form.AcceptButton Property Form.AcceptButton属性

Gets or sets the button on the form that is clicked when the user presses the ENTER key. 获取或设置用户按下ENTER键时单击的表单上的按钮。

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

Additional information 附加信息

For cencel you can use 对于cencel,您可以使用

form1.CancelButton = MyCancelButton;

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM