判断窗体是否已存在实例
2022-03-23 17:26 idea555 阅读(124) 评论(0) 收藏 举报/// <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);
本博客有部分内容来自网络,如有问题请联系:hebeilijianghua@qq.com,并注明来自博客园。

浙公网安备 33010602011771号