Winfrom统一单例窗口
作者:互联网
//调用方式 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; } }
标签:窗口,Name,Winfrom,frm,forms,Instance,static,单例,return 来源: https://www.cnblogs.com/212s/p/15545002.html