super
/// <summary> /// 添加Tab页 /// </summary> /// <param name="frm"></param> private void AddForm(Form frm) { this.superTabControl1.Visible = true; if (!IsOpenTab(frm.Text)) { SuperTabItem tabItem = superTabControl1.CreateTab(frm.Text); SuperTabControlPanel tcp = new SuperTabControlPanel(); tabItem.AttachedControl = tcp; tcp.TabItem = tabItem; tcp.Dock = DockStyle.Fill; tcp.Name = frm.Name + "Tab"; frm.TopLevel = false; frm.Dock = DockStyle.Fill; frm.FormBorderStyle = FormBorderStyle.None; frm.Show(); tcp.Controls.Add(frm); superTabControl1.Controls.Add(tcp); superTabControl1.SelectedTab = tabItem; } } /// <summary> /// 检查是否已打开某个子窗体 /// </summary> /// <param name="tabName"></param> /// <returns></returns> private bool IsOpenTab(string tabName) { bool isOpened = false; foreach (SuperTabItem tab in superTabControl1.Tabs) { if (tab.Text.Trim() == tabName.Trim()) { isOpened = true; superTabControl1.SelectedTab = tab; break; } } return isOpened; }
TabControl
/// <summary> /// 添加Tab页 /// </summary> /// <param name="frm"></param> private void AddForm(LisBaseForm frm) { this.tabControl1.Visible = true; if (!IsOpenTab(frm.Text)) { TabItem tabItem = tabControl1.CreateTab(frm.Text); TabControlPanel tcp = new TabControlPanel(); tabItem.AttachedControl = tcp; tcp.TabItem = tabItem; tcp.Dock = DockStyle.Fill; tcp.Name = frm.Name + "Tab"; frm.TopLevel = false; frm.Dock = DockStyle.Fill; frm.FormBorderStyle = FormBorderStyle.None; frm.Show(); tcp.Controls.Add(frm); tabControl1.Controls.Add(tcp); tabControl1.SelectedTab = tabItem; } } /// <summary> /// 检查是否已打开某个子窗体 /// </summary> /// <param name="tabName"></param> /// <returns></returns> private bool IsOpenTab(string tabName) { bool isOpened = false; foreach (TabItem tab in tabControl1.Tabs) { if (tab.Text.Trim() == tabName.Trim()) { isOpened = true; tabControl1.SelectedTab = tab; break; } } return isOpened; } private void tabControl1_TabRemoved(object sender, EventArgs e) { //tabControl1.Visible = false; int Count = this.tabControl1.Tabs.Count; if (Count == 0) this.tabControl1.Visible = false; }
时间: 2024-10-12 22:06:13