WinForm检测子窗体是否打开过,避免窗体重复打开

private void aboutusView_ItemClick(object sender, EventArgs e)
        {
            CRM.Help.frmAboutUs hpFAU = new CRM.Help.frmAboutUs();
            if (!ShowChildrenForm("关于我们"))
            {
                hpFAU. MdiParent = this;
                hpFAU.Show();
            }
            else
            {
                hpFAU.Activate();
            }
        }
        /// <summary>
        /// 检测子窗体是否打开过
        /// </summary>
        /// <param name="p_ChildrenFormText"></param>
        /// <returns></returns>
        private bool ShowChildrenForm(string p_ChildrenFormText)
        {
            int i;
            //依次检测当前窗体的子窗体
            for (i = 0; i &lt; this.MdiChildren.Length; i++)
            {
                //判断当前子窗体的Text属性值是否与传入的字符串值相同
                if (this. MdiChildren[i].Text == p_ChildrenFormText)
                {
                    //如果值相同则表示此子窗体为想要调用的子窗体,激活此子窗体并返回true值
                    this.MdiChildren[i].Activate();
                    return true;
                }
            }
            //如果没有相同的值则表示要调用的子窗体还没有被打开,返回false值
            return false;
        }

你可能感兴趣的:(职场,WinForm,检测,窗体,休闲)