How to close previous mdi child in parent form

reza akhlaghi picture reza akhlaghi · Nov 3, 2013 · Viewed 12.3k times · Source

I have a mdi parent form and I open my other forms in run time as mdi child form by this code:

private void MenuItem_Click(object sender, EventArgs e)
{
    childform = new childform ();
    frm.MdiParent = Mdiparent;
    frm.WindowState = FormWindowState.Maximized;
    frm.Show();
}

but the problem is: When current form is open, user can open another form and it can be repeated several times so that each form is opened what's code for closing the current child form before user open a new child form??

Answer

reza akhlaghi picture reza akhlaghi · Nov 5, 2013

tanx for ur assist :) I Found effective code by test other Members in Class Windows.forms just enough check this :

if (ActiveMdiChild != null)
    ActiveMdiChild.Close();