C# 关闭时取消休假事件
我在表单上有一个文本框,其中有一个从txPredio_Leave事件调用的方法 我的问题是,用户将焦点放在文本框上,然后通过单击上角的小X close图标或调用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) {
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;
}