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

        <tfoot id='UUvyA'></tfoot>

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

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

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

        检测表单何时关闭c#

        时间:2023-09-15
        1. <tfoot id='oh0ed'></tfoot>

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

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

                <tbody id='oh0ed'></tbody>

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

                  <bdo id='oh0ed'></bdo><ul id='oh0ed'></ul>
                  本文介绍了检测表单何时关闭c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我创建了一个 WinForm,它显示带有按钮的提示.这是一个自定义的 WinForm 视图,因为消息框对话框是不够的.

                  I have a WinForm that I create that shows a prompt with a button. This is a custom WinForm view, as a message box dialog was not sufficient.

                  我有一个后台工作程序已启动并正在运行.如果单击 myForm 上的按钮,我还想退出 while(aBackgroundWorker.IsBusy) 循环.

                  I have a background worker started and running. I also want to exit the while(aBackgroundWorker.IsBusy) loop if the button on myForm was clicked.

                  //MyProgram.cs
                  
                  using(CustomForm myForm = new CustomForm())
                  {
                      myForm.Show(theFormOwner);
                      myForm.Refresh();
                  
                      while(aBackgroundWorker.IsBusy)
                      {
                          Thread.Sleep(1);
                          Application.DoEvents();
                      }
                  }
                  

                  现在,在 CustomFormButton_clicked 事件中,我有

                  Right now, in the CustomForm the Button_clicked event, I have

                  //CustomForm.cs
                  
                  private void theButton_Click(object sender, EventArgs e)
                  {
                    this.Close();
                  }
                  

                  我是否需要向 CustomForm 类或声明和初始化表单的位置添加更多代码才能检测到闭包?

                  Do I need to add more code to the CustomForm class, or the location where I declare and initialize the form in order to be able to detect a closure?

                  推荐答案

                  要检测表单何时真正关闭,需要挂钩 FormClosed 事件:

                  To detect when the form is actually closed, you need to hook the FormClosed event:

                      this.FormClosed += new FormClosedEventHandler(Form1_FormClosed);
                  
                      void Form1_FormClosed(object sender, FormClosedEventArgs e)
                      {
                          // Do something
                      }
                  

                  或者:

                  using(CustomForm myForm = new CustomForm())
                  {
                      myForm.FormClosed += new FormClosedEventHandler(MyForm_FormClosed);
                      ...
                  }
                  
                  void MyForm_FormClosed(object sender, FormClosedEventArgs e)
                  {
                      // Do something
                  }
                  

                  这篇关于检测表单何时关闭c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:带有自定义参数的 EventHandler 下一篇:事件触发次数越来越多

                  相关文章

                  <tfoot id='0xZVL'></tfoot>
                    <bdo id='0xZVL'></bdo><ul id='0xZVL'></ul>

                • <legend id='0xZVL'><style id='0xZVL'><dir id='0xZVL'><q id='0xZVL'></q></dir></style></legend>

                  1. <small id='0xZVL'></small><noframes id='0xZVL'>

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