This post was useful to me, although my case was a little different.
In this case, avoidance _currentForm.Hide(); works fine because the code does the form switcher. I found that the problem is also related to MDIChild, which was hidden by another MDIChild, which is on top.
Here's a workaround that works in this case too, based on the fact that Dispose always called.
You can do something like this:
public abstract class FormExtenderClass : Form{ private bool formClosingFired = false; private bool formClosedFired = false; protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); formClosingFired = !e.Cancel; } protected override void OnFormClosed(FormClosedEventArgs e) { base.OnFormClosed(e); formClosingFired = true; } protected override void Dispose(bool disposing) { if (!formClosingFired) OnFormClosing(new FormClosingEventArgs(CloseReason.UserClosing, false)); if (!formClosedFired) OnFormClosed(new FormClosedEventArgs(CloseReason.UserClosing)); base.Dispose(disposing); } }
Then in the MDIChildren code just change the first line from
public partial class AutoForm : Form {
to
public partial class AutoForm : FormExtenderClass {
Consider this a concern anyway. The main difference is that set e.Cancel=true will have no effect when FormClosing is called from Disposed as backup.
source share