/// <summary> /// 关闭标签页显示的窗体 /// </summary> /// <param name="frmShow">显示的窗体</param> /// <param name="typeParent">父窗体类型</param> /// <param name="CloseStyle">关闭方式 1-存在父窗体则激活;2-存在父窗体则激活,不存在父窗体则重建</param> public static void CloseTabPageForm(Form frmShow, Type typeParent = null, int CloseStyle = 1) { try { if (frmShow == null || frmShow.Parent == null || !(frmShow.Parent is TabPage)) { return; } TabPage tp = frmShow.Parent as TabPage; if (tp.Parent == null || !(tp.Parent is TabControl)) { return; } if (typeParent == null) { MenuInfo menu = Login.Login_Var.lstMenu.FirstOrDefault(t => t.ProjectName == frmShow.GetType().Name); if (menu == null) { return; } MenuInfo parent = Login.Login_Var.lstMenu.FirstOrDefault(t => t.ID == menu.ParentID); if (parent == null) { return; } typeParent = frmShow.GetType().Assembly.GetType(Basic.Basic_Var.dicFormPath[parent.ProjectName]); } TabControl tc = tp.Parent as TabControl; foreach (TabPage p in tc.TabPages) { if (p.Controls != null && p.Controls.Count >= 1) { if (p.Controls[0].GetType() == typeParent) { tc.SelectedTab = p; return; } } } if (CloseStyle == 2) { Form frm = (Form)Activator.CreateInstance(typeParent); FrmMainTab frmMain = tc.TopLevelControl as FrmMainTab; frmMain.ShowForm(frm.Text, frm); } } catch (Exception ex) { ErrorMessage(ex.Message); } finally { //frmShow.Close(); } }
public static void ShowTabPageForm(Form frmParent, Form frmShow, int OpenStyle = 1) { try { object obj = frmParent.Parent.Parent.Parent.Parent.Parent; if (obj == null || obj.GetType().Name != typeof(FrmMainTab).Name) { return; } FrmMainTab frmMain = obj as FrmMainTab; frmMain.ShowForm(frmShow.Text, frmShow, OpenStyle); } catch (Exception ex) { ErrorMessage(ex.Message); } }