You can change the void Dispose(bool disposing)
method in your winform to close your child form instead, like this:
protected override void Dispose(bool disposing)
{
if (/* you need to close a child form */)
{
// close the child form, maybe by calling its Dispose method
}
else
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
}
EDIT: as my commenter said, instead of modifying the overridden Dispose
method, you should just override the OnFormClosing
method instead, like so:
protected override void OnFormClosing(FormClosingEventArgs e)
{
if (/* you need to close the child form */)
{
e.Cancel = true;
// close the child form, maybe with childForm.Close();
}
else
base.OnFormClosing(e);
}