I have an usercontrol which is being used inside an MDI child. I am changing the visibility of that MDI child when it is closed by doing this.
private void MDIChild_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Visible = false;
}
But when I change the visibility of the MDI form to true, the user control load event is fired even though the form load isn’t fired. But this does not happen in case of a normal windows form.
Basically I need to disable the close feature of my MDI child in some cases.
Any idea how to do this?
From the MSDN Documentation for the UserControl Load event
So, when you show the MDI form, this criteria is met. It means that, in this instance, if you are relying on the Load event for the UserControl, you should instead move it to another method and call that explicitly when your MDI form is shown.