Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent duplicate MDI children forms

Tags:

c#

children

mdi

Is there a way to prevent the opening of a certain form within an MDI container if that said form is already opened?

like image 987
user Avatar asked Oct 12 '09 08:10

user


1 Answers

You can interate over the OpenForms collection to check if there is already a form of the given type:

foreach (Form form in Application.OpenForms)
{
    if (form.GetType() == typeof(MyFormType))
    {
        form.Activate();
        return;
    }
}

Form newForm = new MyFormType();
newForm.MdiParent = this;
newForm.Show();
like image 67
Fredrik Mörk Avatar answered Oct 20 '22 20:10

Fredrik Mörk