且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

防止重复MDI子窗体

更新时间:2023-12-06 08:34:16

您可以interate在OpenForms集合,以检查是否已存在给定类型的一种形式:

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();