公告
财富商城
积分规则
提问
发文
2019-01-03 05:53发布
地球回转人心会变
This question already has an answer here:
How to hide TabPage from TabControl in WinForms 2.0?
No, this doesn't exist. You have to remove the tab and re-add it when you want it. Or use a different (3rd-party) tab control.
Not sure about "Winforms 2.0" but this is tried and proven:
http://www.mostthingsweb.com/2011/01/hiding-tab-headers-on-a-tabcontrol-in-c/
Code Snippet for Hiding a TabPage
private void HideTab1_Click(object sender, EventArgs e) { tabControl1.TabPages.Remove(tabPage1); }
Code Snippet for Showing a TabPage
private void ShowTab1_Click(object sender, EventArgs e) { tabControl1.TabPages.Add(tabPage1); }
I combined the answer from @Jack Griffin and the one from @amazedsaint (the dotnetspider code snippet respectively) into a single TabControlHelper.
The TabControlHelper lets you:
public class TabControlHelper { private TabControl _tabControl; private List<KeyValuePair<TabPage, int>> _pagesIndexed; public TabControlHelper(TabControl tabControl) { _tabControl = tabControl; _pagesIndexed = new List<KeyValuePair<TabPage, int>>(); for (int i = 0; i < tabControl.TabPages.Count; i++) { _pagesIndexed.Add(new KeyValuePair<TabPage, int> (tabControl.TabPages[i], i )); } } public void HideAllPages() { for (int i = 0; i < _pagesIndexed.Count; i++) { _tabControl.TabPages.Remove(_pagesIndexed[i].Key); } } public void ShowAllPages() { for (int i = 0; i < _pagesIndexed.Count; i++) { _tabControl.TabPages.Add(_pagesIndexed[i].Key); } } public void HidePage(TabPage tabpage) { if (!_tabControl.TabPages.Contains(tabpage)) return; _tabControl.TabPages.Remove(tabpage); } public void ShowPage(TabPage tabpage) { if (_tabControl.TabPages.Contains(tabpage)) return; InsertTabPage(GetTabPage(tabpage).Key, GetTabPage(tabpage).Value); } private void InsertTabPage(TabPage tabpage, int index) { if (index < 0 || index > _tabControl.TabCount) throw new ArgumentException("Index out of Range."); _tabControl.TabPages.Add(tabpage); if (index < _tabControl.TabCount - 1) do { SwapTabPages(tabpage, (_tabControl.TabPages[_tabControl.TabPages.IndexOf(tabpage) - 1])); } while (_tabControl.TabPages.IndexOf(tabpage) != index); _tabControl.SelectedTab = tabpage; } private void SwapTabPages(TabPage tabpage1, TabPage tabpage2) { if (_tabControl.TabPages.Contains(tabpage1) == false || _tabControl.TabPages.Contains(tabpage2) == false) throw new ArgumentException("TabPages must be in the TabControls TabPageCollection."); int Index1 = _tabControl.TabPages.IndexOf(tabpage1); int Index2 = _tabControl.TabPages.IndexOf(tabpage2); _tabControl.TabPages[Index1] = tabpage2; _tabControl.TabPages[Index2] = tabpage1; } private KeyValuePair<TabPage, int> GetTabPage(TabPage tabpage) { return _pagesIndexed.Where(p => p.Key == tabpage).First(); } }
TabPage pageListe, pageDetay; bool isDetay = false; private void btnListeDetay_Click(object sender, EventArgs e) { if (isDetay) { isDetay = false; tc.TabPages.Remove(tpKayit); tc.TabPages.Insert(0,pageListe); } else { tc.TabPages.Remove(tpListe); tc.TabPages.Insert(0,pageDetay); isDetay = true; } }
private System.Windows.Forms.TabControl _tabControl; private System.Windows.Forms.TabPage _tabPage1; private System.Windows.Forms.TabPage _tabPage2; ... // Initialise the controls ... // "hides" tab page 2 _tabControl.TabPages.Remove(_tabPage2); // "shows" tab page 2 // if the tab control does not contain tabpage2 if (! _tabControl.TabPages.Contains(_tabPage2)) { _tabControl.TabPages.Add(_tabPage2); }
最多设置5个标签!
No, this doesn't exist. You have to remove the tab and re-add it when you want it. Or use a different (3rd-party) tab control.
Not sure about "Winforms 2.0" but this is tried and proven:
http://www.mostthingsweb.com/2011/01/hiding-tab-headers-on-a-tabcontrol-in-c/
Code Snippet for Hiding a TabPage
Code Snippet for Showing a TabPage
I combined the answer from @Jack Griffin and the one from @amazedsaint (the dotnetspider code snippet respectively) into a single TabControlHelper.
The TabControlHelper lets you: