Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 关闭时取消休假事件_C#_.net_Winforms_Textbox_Events - Fatal编程技术网

C# 关闭时取消休假事件

C# 关闭时取消休假事件,c#,.net,winforms,textbox,events,C#,.net,Winforms,Textbox,Events,我在表单上有一个文本框,其中有一个从txPredio_Leave事件调用的方法 我的问题是,用户将焦点放在文本框上,然后通过单击上角的小X close图标或调用this.ActiveMdiChild.close()关闭表单或通过调用 private void mnucerrarTodas_Click(object sender, EventArgs e) { foreach (Form form in this.MdiChildren) {

我在表单上有一个文本框,其中有一个从txPredio_Leave事件调用的方法

我的问题是,用户将焦点放在文本框上,然后通过单击上角的小X close图标或调用
this.ActiveMdiChild.close()关闭表单或通过调用

    private void mnucerrarTodas_Click(object sender, EventArgs e)
    {
        foreach (Form form in this.MdiChildren)
        {
            form.Close();
        }
    }
txPredio离开执行该方法。。那么我不需要在表单关闭时执行此方法

我认为一个解决办法是在休假事件中询问是否关闭表单

        private void txPredio_Leave(object sender, EventArgs e)
        {  
            if(!form is closing)//pseudo code
               Check_Load_Predio();
        }
或者其他解决方案可以是

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    {   
       //code for cancel the txPredio_Leave event
    }

这个解决方案对我不起作用。然后我需要一个解决我的问题的方法。提前感谢

尝试删除
表单关闭中的
离开
处理程序

编辑:如下所示:

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{   
    txPredio.Leave -= txPredio_Leave;
}

尝试删除
FormClosing
中的
Leave
处理程序

编辑:如下所示:

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{   
    txPredio.Leave -= txPredio_Leave;
}