为什么在单击关闭按钮两次之前,我的表单才会关闭

时间:2017-10-23 16:24:34

标签: winforms

我们有一个名为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结算活动中,我们首先检查该RecentlyBilled表单是否已打开,如果是,请关闭它:

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 MDI子表单保持打开状态,直到再次单击其[X]按钮。

这是因为RecentlyBilled表单尚未处理,并且引用了打开它并将动作传递给它的Notes表单?

0 个答案:

没有答案