var frm = Activator.CreateInstance<T>();
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="pnlFrm"></param> /// <param name="isQuery"> true调用查询方法</param> /// <returns></returns> public static bool SetTopUIForm<T>(UIPanel pnlFrm, bool isQuery = true) where T : UIForm { try { MsgBox.ShowWaitForm(); UIForm frm = null; foreach (var s in pnlFrm.Controls) { if (s is T) { frm = s as UIForm; frm.Visible = true; } else { var f = s as UIForm; f.Visible = false; } } if (frm == null) { frm = Activator.CreateInstance<T>(); } if(isQuery) { IQuery iq = frm as IQuery; iq?.QueryMain(); } frm.TopMost = true; frm.TopLevel = false; frm.ShowTitle = false; frm.FormBorderStyle = FormBorderStyle.None; frm.Dock = DockStyle.Fill; frm.Parent = pnlFrm; frm.Show(); MsgBox.HideWaitForm(); //pnlFrm.Controls.Clear(); } catch (Exception ex) { MsgBox.ShowError(ex.Message); } finally { MsgBox.HideWaitForm(); } return true; }
标签:C#,MsgBox,frm,pnlFrm,泛型,New,UIForm,true From: https://www.cnblogs.com/yuanshuo/p/18010782