方式一,
foreach (Form frm in Application.OpenForms) { if (frm is form1) { form1.Activate(); form1.WindowState = FormWindowState.Normal; return; } } Form1 form1 = new Form1(); form1.Show();
方式二,
Form1 F1 ; if(F1 == null || F1.IsDisposed) { F1 = new Form1(); F1.Show();//未打开,直接打开。 } else { F1.Activate();//已打开,获得焦点,置顶。 }
方式三,
public class GenericSingleton<T> where T : Form, new() { private static T t = null; public static T CreateInstrance() { if (t == null || t.IsDisposed) { t = new T(); } else { t.Activate(); //如果已经打开过就让其获得焦点 t.WindowState = FormWindowState.Normal;//使Form恢复正常窗体大小 } return t; } }
Form2 form2 = GenericSingleton<Form2>.CreateInstrance(); form2.Show();
标签:F1,null,c#,Form1,form1,窗体,new,打开,Winform From: https://www.cnblogs.com/qingjiawen/p/17468925.html