<bdo id='wen9g'></bdo><ul id='wen9g'></ul>

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

    <small id='wen9g'></small><noframes id='wen9g'>

    1. 如何取消winforms中的任何事件?

      时间:2023-09-16
      <i id='2RpLl'><tr id='2RpLl'><dt id='2RpLl'><q id='2RpLl'><span id='2RpLl'><b id='2RpLl'><form id='2RpLl'><ins id='2RpLl'></ins><ul id='2RpLl'></ul><sub id='2RpLl'></sub></form><legend id='2RpLl'></legend><bdo id='2RpLl'><pre id='2RpLl'><center id='2RpLl'></center></pre></bdo></b><th id='2RpLl'></th></span></q></dt></tr></i><div id='2RpLl'><tfoot id='2RpLl'></tfoot><dl id='2RpLl'><fieldset id='2RpLl'></fieldset></dl></div>
    2. <tfoot id='2RpLl'></tfoot>
        <bdo id='2RpLl'></bdo><ul id='2RpLl'></ul>

          <small id='2RpLl'></small><noframes id='2RpLl'>

              <tbody id='2RpLl'></tbody>

            • <legend id='2RpLl'><style id='2RpLl'><dir id='2RpLl'><q id='2RpLl'></q></dir></style></legend>
                本文介绍了如何取消winforms中的任何事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想取消该函数范围内的事件.

                I want to cancel an event from within that function scope.

                例如.我按下按钮单击事件并在错误验证时,我想取消此事件.同样,我也想取消其他活动.

                Eg. I pressed button click event and on false validation, I want to cancel this event. Likewise i want to cancel other events also.

                我如何在 C# 中做到这一点

                How can i do this in C#

                推荐答案

                视场景而定;在大多数情况下:而不是 cancel 事件,什么也不做,例如:

                It depends on the scenario; in most cases: rather than cancel the event, just do nothing, for example:

                private void SaveDataClicked(object sender, EventArgs args) {
                    if(!ValidateData()) return;
                    // [snip: code that does stuff]
                }
                

                或:

                private void SaveDataClicked(object sender, EventArgs args) {
                    if(ValidateData()) {
                        // [snip: code that does stuff]
                    }
                }
                

                有些事件会暴露 CancelEventArgs(或类似的),允许通过 args 取消一些 外部 行为 - 形式 -关闭是最明显的例子(设置 e.Cancel = true;).

                There are some events that expose a CancelEventArgs (or similar), allowing to to cancel some external behaviour via the args - form-closing being the most obvious example (set e.Cancel = true;).

                请注意,在这种情况下,我不会在按钮上显示自动对话结果;当(如果)处理程序成功完成时手动应用.

                Note that in this scenario I would not have an automatic dialog-result on the button; apply that manually when (if) the handler completes successfully.

                这篇关于如何取消winforms中的任何事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:控制台应用程序 C# 的关闭事件 下一篇:为什么对 EventHandler&lt;TEventArgs&gt; 没有约束?

                相关文章

              1. <legend id='91RXH'><style id='91RXH'><dir id='91RXH'><q id='91RXH'></q></dir></style></legend>
                    <bdo id='91RXH'></bdo><ul id='91RXH'></ul>

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

                    <small id='91RXH'></small><noframes id='91RXH'>

                  2. <tfoot id='91RXH'></tfoot>