• <small id='bQKy4'></small><noframes id='bQKy4'>

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

      1. 如何取消winform按钮点击事件?

        时间:2023-06-05
          <i id='x0HY2'><tr id='x0HY2'><dt id='x0HY2'><q id='x0HY2'><span id='x0HY2'><b id='x0HY2'><form id='x0HY2'><ins id='x0HY2'></ins><ul id='x0HY2'></ul><sub id='x0HY2'></sub></form><legend id='x0HY2'></legend><bdo id='x0HY2'><pre id='x0HY2'><center id='x0HY2'></center></pre></bdo></b><th id='x0HY2'></th></span></q></dt></tr></i><div id='x0HY2'><tfoot id='x0HY2'></tfoot><dl id='x0HY2'><fieldset id='x0HY2'></fieldset></dl></div>

            1. <legend id='x0HY2'><style id='x0HY2'><dir id='x0HY2'><q id='x0HY2'></q></dir></style></legend>
            2. <tfoot id='x0HY2'></tfoot>

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

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

                    <tbody id='x0HY2'></tbody>
                  本文介绍了如何取消winform按钮点击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有一个继承自 System.Windows.Forms.Button 的自定义按钮类.

                  I have a custom button class inherited from System.Windows.Forms.Button.

                  我想在我的 winform 项目中使用这个按钮.

                  I want to use this button in my winform project.

                  这个类叫做ConfirmButton",它用Yes或No显示确认信息.

                  This class is called "ConfirmButton", and it shows confirm message with Yes or No.

                  但问题是当用户选择否并确认消息时,我不知道如何停止点击事件.

                  But the problem is that I do not know how to stop click event when user selected No with confirm message.

                  这是我的课程来源.

                  using System;
                  using System.ComponentModel;
                  using System.Windows.Forms;
                  
                  namespace ConfirmControlTest
                  {
                      public partial class ConfirmButton : System.Windows.Forms.Button
                      {
                          public Button()
                          {
                              InitializeComponent();
                  
                              this.Click  += Button_Click;
                          }
                  
                          void Button_Click(object sender, EventArgs e)
                          {
                              DialogResult res    = MessageBox.Show("Would you like to run the command?"
                                  , "Confirm"
                                  , MessageBoxButtons.YesNo
                                  );
                              if (res == System.Windows.Forms.DialogResult.No)
                              {
                                  // I have to cancel button click event here
                  
                              }
                          }
                      }
                  }
                  

                  如果用户从确认消息中选择否,则按钮单击事件不应再触发.

                  If user select No from confirm message, then the button click event should not fire anymore.

                  推荐答案

                  你需要重写点击事件.

                  class ConfirmButton:Button
                      {
                      public ConfirmButton()
                      {
                  
                      }
                  
                      protected override void OnClick(EventArgs e)
                      {
                          DialogResult res = MessageBox.Show("Would you like to run the command?", "Confirm", MessageBoxButtons.YesNo
                              );
                          if (res == System.Windows.Forms.DialogResult.No)
                          {
                              return;
                          }
                          base.OnClick(e);
                      }
                  }
                  

                  这篇关于如何取消winform按钮点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:多个提交按钮点击问题? 下一篇:将 OnClick 事件添加到 ASP.NET 控件

                  相关文章

                  最新文章

                  <legend id='zn8tD'><style id='zn8tD'><dir id='zn8tD'><q id='zn8tD'></q></dir></style></legend>

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

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

                    1. <tfoot id='zn8tD'></tfoot>

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