<i id='AgVMg'><tr id='AgVMg'><dt id='AgVMg'><q id='AgVMg'><span id='AgVMg'><b id='AgVMg'><form id='AgVMg'><ins id='AgVMg'></ins><ul id='AgVMg'></ul><sub id='AgVMg'></sub></form><legend id='AgVMg'></legend><bdo id='AgVMg'><pre id='AgVMg'><center id='AgVMg'></center></pre></bdo></b><th id='AgVMg'></th></span></q></dt></tr></i><div id='AgVMg'><tfoot id='AgVMg'></tfoot><dl id='AgVMg'><fieldset id='AgVMg'></fieldset></dl></div>
    • <bdo id='AgVMg'></bdo><ul id='AgVMg'></ul>
    <tfoot id='AgVMg'></tfoot>

    1. <small id='AgVMg'></small><noframes id='AgVMg'>

    2. <legend id='AgVMg'><style id='AgVMg'><dir id='AgVMg'><q id='AgVMg'></q></dir></style></legend>

      OK-Cancel Dialog:处理“Enter"键按下

      时间:2023-09-14

        <legend id='xgIDS'><style id='xgIDS'><dir id='xgIDS'><q id='xgIDS'></q></dir></style></legend>
        • <i id='xgIDS'><tr id='xgIDS'><dt id='xgIDS'><q id='xgIDS'><span id='xgIDS'><b id='xgIDS'><form id='xgIDS'><ins id='xgIDS'></ins><ul id='xgIDS'></ul><sub id='xgIDS'></sub></form><legend id='xgIDS'></legend><bdo id='xgIDS'><pre id='xgIDS'><center id='xgIDS'></center></pre></bdo></b><th id='xgIDS'></th></span></q></dt></tr></i><div id='xgIDS'><tfoot id='xgIDS'></tfoot><dl id='xgIDS'><fieldset id='xgIDS'></fieldset></dl></div>

          1. <small id='xgIDS'></small><noframes id='xgIDS'>

            • <bdo id='xgIDS'></bdo><ul id='xgIDS'></ul>
              <tfoot id='xgIDS'></tfoot>
                <tbody id='xgIDS'></tbody>

                本文介绍了OK-Cancel Dialog:处理“Enter"键按下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在 Winforms 中构建一个 Dialog.当您创建它时,它有两个确定和取消按钮,这就是我想要的.在这个对话框中,我还有一个处理其 KeyPress 事件的 TextBox 和一个 Sub(在 VB.NET 中编码).当按下Enter"键时,我需要一些事情发生.

                I'm building a Dialog in Winforms. It's got the two OK and Cancel buttons that are there when you create it, which is what I want. In this dialog I also have a TextBox and a Sub (coding in VB.NET) that handles its KeyPress event. I need stuff to happen when the 'Enter' key is pressed.

                现在,我已经一次又一次地完成了这样的 KeyPress 处理.但是,这种情况有所不同,因为只要按下Enter"键,对话框就会自动假定您正在按下确定"按钮,返回结果并关闭.在设计器和运行应用程序时的实际表单中,OK 按钮都是突出显示的,这意味着它始终具有某种焦点(因为没有更好的术语).如何禁用对话框的此功能?当我调试我的代码时,按回车键甚至没有到达处理 KeyPress 事件的子程序.它只是关闭对话框并返回结果,因此我无法真正单步执行代码并查看幕后发生的情况.

                Now, I've done such KeyPress handling times and times again. This situation, however, is different, because as soon as 'Enter' key is pressed, the dialog automatically assumes you're pressing the 'OK' button, returns a result and closes. In both the Designer and the actual form when running the application, the OK button is highlight, which means is has some kind of a focus (for the lack of a better term) at all times. How can I disable this feature of a dialog? When I debug my code, pressing enter does not even get to the sub handling the KeyPress event. It simply closes the dialog and returns the result, therefore I can't really step through the code and see what happens behind the scenes.

                要重申这个问题,我该如何禁用此功能?

                To restate the question, how can I disable this functionality?

                干杯!= )

                推荐答案

                这是它应该的工作方式.您应该将表单的 AcceptButton 属性设置为 OK 按钮.它获取粗边框以指示它是默认按钮,其 Click 事件在用户按 Enter 时自动运行.如果您将按钮的 DialogResult 属性设置为 OK,那么它还会自动分配 DialogResult 属性以便对话框关闭.

                This is the way it is supposed to work. You should set the form's AcceptButton property to the OK button. It gets the fat border to indicate that it is the default button whose Click event automatically runs when the user presses Enter. If you set the button's DialogResult property to OK then it also assigns the DialogResult property automatically so that the dialog closes.

                不要修复它.如果要调试它,请在按钮的 Click 事件处理程序上设置中断.如果您想阻止它关闭,请重置按钮的 DialogResult 属性或将表单的 DialogResult 属性设置回 None.永远不要使用 KeyPressed 事件.

                Don't fix it. If you want to debug it then set a break on the button's Click event handler. If you want to prevent it from closing then either reset the button's DialogResult property or set the form's DialogResult property back to None. Never use the KeyPressed event.

                这篇关于OK-Cancel Dialog:处理“Enter"键按下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 BackgroundWorker 运行时显示模态窗口,而不会出现 STA/MTA 问题 下一篇:在 Asp.net 网页中显示保存文件对话框

                相关文章

              • <legend id='w3JFO'><style id='w3JFO'><dir id='w3JFO'><q id='w3JFO'></q></dir></style></legend>
                <i id='w3JFO'><tr id='w3JFO'><dt id='w3JFO'><q id='w3JFO'><span id='w3JFO'><b id='w3JFO'><form id='w3JFO'><ins id='w3JFO'></ins><ul id='w3JFO'></ul><sub id='w3JFO'></sub></form><legend id='w3JFO'></legend><bdo id='w3JFO'><pre id='w3JFO'><center id='w3JFO'></center></pre></bdo></b><th id='w3JFO'></th></span></q></dt></tr></i><div id='w3JFO'><tfoot id='w3JFO'></tfoot><dl id='w3JFO'><fieldset id='w3JFO'></fieldset></dl></div>

                  • <bdo id='w3JFO'></bdo><ul id='w3JFO'></ul>

                  <tfoot id='w3JFO'></tfoot>
                1. <small id='w3JFO'></small><noframes id='w3JFO'>