防止重复MDI子窗体 [英] Prevent duplicate MDI children forms

查看:136
本文介绍了防止重复MDI子窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法阻止某种形式的如果说形式已经打开一个MDI容器内的开?

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

推荐答案

您可以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();

这篇关于防止重复MDI子窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆