winForm中使用MDI窗体

在Mdi窗体中,使一个窗体的实例只显示一次,调用时,如果已经存在,则显示原来存在的窗体,如果不存在,直接显示新窗体:

            Show1 s1 = new Show1();
            s1.Tag = "s1";
            bool isExists = false;
            foreach(Form f1 in this.MdiChildren)
            {
                if (f1.Tag.ToString() == "s1")
                {
                    isExists = true;
                    f1.Activate();
                    break;
                }
            }
            if (!isExists)
            {
                s1.MdiParent = this;
                s1.Text = ((ButtonItem)sender).Text;
                s1.Show();
            }
原文地址:https://www.cnblogs.com/wjhx/p/1785922.html