/// <summary> /// Helper to remove a tab entry. /// </summary> /// <param name="tabNumber">The tab number of the tab entry to remove.</param> private void RemoveTabEntry(int tabNumber) { // Locate the tab entry for the specified tab number. It it's found, remove it. TabEntry tabEntry = (TabEntry)tabEntryList[tabNumber]; if (tabEntry != null) { if (SelectedTabEntry == tabEntry) { SelectedTabEntry = FirstTabEntry; } tabPageContainerControl.Controls.Remove(tabEntry.TabPageControl); LightweightControls.Remove(tabEntry.TabSelectorLightweightControl); tabEntryList.Remove(tabNumber); } }
/// <summary> /// Sets a tab control. /// </summary> /// <param name="index">The tab index to set.</param> /// <param name="tabPageControl">The tab page control to set.</param> public void SetTab(int tabNumber, TabPageControl tabPageControl) { // If there already is a tab entry for the specified tab number, remove it. RemoveTabEntry(tabNumber); // Instantiate the new tab entry. TabEntry tabEntry = new TabEntry(this, tabPageControl); tabEntryList.Add(tabNumber, tabEntry); tabPageContainerControl.Controls.Add(tabEntry.TabPageControl); LightweightControls.Add(tabEntry.TabSelectorLightweightControl); tabEntry.TabSelectorLightweightControl.DragInside += new DragEventHandler(TabSelectorLightweightControl_DragInside); tabEntry.TabSelectorLightweightControl.DragOver += new DragEventHandler(TabSelectorLightweightControl_DragOver); tabEntry.TabSelectorLightweightControl.Selected += new EventHandler(TabSelectorLightweightControl_Selected); tabEntry.TabPageControl.VisibleChanged += new EventHandler(TabPageControl_VisibleChanged); // Layout and invalidate. PerformLayout(); Invalidate(); }