为什么在关闭按钮两次之前不会关闭我的表格

问题描述 投票:0回答:1
我们有一个名为

Notes

的MDI儿童形式,它以这种方式打开另一种形式:

private void OpenRecentlyBilled() { if (Application.OpenForms.OfType<RecentlyBilled>().Count() == 1) return; Action<string, Form> lookupAction = (anoncode, form) => { Lookup(anoncode); }; var F = new RecentlyBilled(lookupAction); F.Show(this); }
在结束事件中,我们首先检查该表格是否打开,如果是的,则将其关闭:

Notes
the形式关闭,但是
RecentlyBilled

mDi子形式保持打开状态,直到第二次单击其[x]按钮。
这是因为
private void Notes_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = false; if (Application.OpenForms.OfType<RecentlyBilledCases>().Count() > 0) { foreach (RecentlyBilled f in Application.OpenForms.OfType<RecentlyBilled>()) { f.Close(); } } }

表格尚未被处置,并且提到了打开它并通过诉讼的

RecentlyBilled
表格?

    

其他人在评论中提到的,您的问题是由近距离事件的形式无意中修改
Notes
集合引起的:

RecentlyBilled
winforms
1个回答
0
投票
将枚举克隆到单独的列表中

Notes

是一个简单的解决方案:

OpenForms
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.