/// <summary>判断窗体是否已存在实例
        /// 
        /// </summary>
        /// <param name="type">窗体类型</param>
        /// <returns></returns>
        public static Form ExistedForm(Type type)
        {
            return Application.OpenForms.Cast<Form>().FirstOrDefault(form => form.GetType() == type);
        }

使用方法:

            Form isExist = ExistedForm(typeof(Form1));
            if (isExist == null)
            {
                Form1 Frm = new Form1();
                Frm.Show();
            }
            else
            {
                isExist.WindowState = FormWindowState.Normal;
                isExist.Activate();
            }

 窗体仅显示一个

            FrmInfo frmInfo = GenericSingleton<FrmInfo>.CreateInstrance();
       frmInfo.Show(this);

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
  • 2021-12-27
  • 2022-01-24
  • 2022-12-23
  • 2021-05-29
  • 2022-03-08
猜你喜欢
  • 2022-02-02
  • 2021-08-21
  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
相关资源
相似解决方案