//调用方式 var frm = new MyForm().Instance(); public static class ExFrm { static Dictionary<string, Form> forms = new Dictionary<string, Form>(); /// <summary> /// 单例模式 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="frm"></param> /// <returns></returns> public static T Instance<T>(this T frm) where T : Form { frm.FormClosed += (s, e) => frm.Dispose(); if (forms.ContainsKey(frm.Name) == false) { forms.Add(frm.Name, frm); return frm; } if (forms[frm.Name].IsDisposed) { forms[frm.Name] = frm; return frm; } frm.Close(); return forms[frm.Name] as T; } }