Avoid duplicate child form in MDI

How do I check to see if a child form is already displayed so I don't have two instances showing?

// MyChildForm is the one I'm looking for

MyChildForm childForm = null;
foreach(Form f in this.MdiChildren)
{
if(f is MyChildForm)
{
// found it
childForm = (MyChildForm) f;
break;
}
}

if( childForm != null)
{
childForm.Show();
childForm.Focus();
}
else
{
childForm = new MyChildForm();
childForm.MdiParent = this;
childForm.Show();
childForm.Focus();
}

1 comments :

Post a Comment