In the MDI container form add the following code
Code:
public void windowClosed(Form closingForm)
{
// get the child forms
Form[] children = this.MdiChildren;
// work back thro the stack of forms
for(int i=children.Length -1; i>-1; i--)
{
Form child = children[i];
// if this child is not the closing form
if (! child.Equals(closingForm))
{
// if the next child is the same type as the closing form then bring it up to top
if (child.GetType().Equals(closingForm.GetType()))
{
child.BringToFront();
break;
}
}
}
}
In each if the child forms add the following code to the Closed event
Code:
private void FormXXX_Closed(object sender, System.EventArgs e)
{
((FormContainer)this.ParentForm).windowClosed(this);
}