/// <summary> /// 关闭选中分页 /// </summary> private void RemoveSelectedTab(object sender, FormClosedEventArgs e) { FormCollection formList = Application.OpenForms; BaseMainForm mdiMainForm = null; BaseRibbonForm mdiRibbonForm = null; foreach (Form frm in formList) { if (frm.Name == "FrmRDIFrameworkNav" || frm.Name == "FrmRDIFrameworkTree") { mdiMainForm = frm as BaseMainForm; break; } if (frm.Name == "FrmRDIFrameworkRibbon") { mdiRibbonForm = frm as BaseRibbonForm; break; } } if (mdiMainForm != null) { if (mdiMainForm.MainTableControl.SelectedTabIndex <= 0) { return; } mdiMainForm.MainTableControl.Tabs.Remove(mdiMainForm.MainTableControl.SelectedTab); } if (mdiRibbonForm != null) { if (mdiRibbonForm.MainTableControl.SelectedTabIndex <= 0) { return; } mdiRibbonForm.MainTableControl.Tabs.Remove(mdiRibbonForm.MainTableControl.SelectedTab); } this.DialogResult = System.Windows.Forms.DialogResult.OK; }
/// <summary> /// 把窗体显示在主界面的Tab中 /// 实例如打开增加用户的窗体: /// var frmUserAdd = new FrmUserAdd(); /// this.ShowFormInMainTab(frmUserAdd, "FrmUserAdd", frmUserAdd.Icon.ToBitmap()); /// </summary> /// <param name="mdiForm">窗体</param> /// <param name="code">窗体编辑</param> /// <param name="pageImage">窗体图标</param> public void ShowFormInMainTab(BaseForm mdiForm, string code, Image pageImage) { var tabItemNew = new SuperTabItem(); var tabControlPanelNew = new SuperTabControlPanel { AutoScroll = true, Dock = DockStyle.Fill, Name = code, TabItem = tabItemNew }; tabItemNew.AttachedControl = tabControlPanelNew; tabItemNew.Name = code; mdiForm.FormClosed += RemoveSelectedTab; mdiForm.FormBorderStyle = FormBorderStyle.None; mdiForm.TopLevel = false; mdiForm.Parent = tabControlPanelNew; mdiForm.Dock = DockStyle.Fill; tabControlPanelNew.Controls.Add(mdiForm); mdiForm.Show(); mdiForm.AutoSize = true; tabItemNew.Text = mdiForm.Text; if (pageImage != null) { tabItemNew.Image = ImageHelper.Scale(pageImage, new Size(24, 24)); //把图标缩放到24*24的尺寸 } FormCollection formList = Application.OpenForms; BaseMainForm mdiMainForm = null; BaseRibbonForm mdiRibbonForm = null; foreach (Form frm in formList) { if (frm.Name == "FrmRDIFrameworkNav" || frm.Name == "FrmRDIFrameworkTree") { mdiMainForm = frm as BaseMainForm; break; } if (frm.Name == "FrmRDIFrameworkRibbon") { mdiRibbonForm = frm as BaseRibbonForm; break; } } if (mdiMainForm != null) { mdiMainForm.MainTableControl.Controls.Add(tabControlPanelNew); mdiMainForm.MainTableControl.Tabs.Add(tabItemNew); mdiMainForm.MainTableControl.Refresh(); mdiMainForm.MainTableControl.SelectedTab = tabItemNew; } if (mdiRibbonForm != null) { mdiRibbonForm.MainTableControl.Controls.Add(tabControlPanelNew); mdiRibbonForm.MainTableControl.Tabs.Add(tabItemNew); mdiRibbonForm.MainTableControl.Refresh(); mdiRibbonForm.MainTableControl.SelectedTab = tabItemNew; } }