/// <summary>Close/Remove Current TabPage</summary> /// <param name="tc">TabControl Name</param> public void Close_Current(TabControl tc) { int CurrentTabIndex = tc.SelectedIndex; // determine previous tab index number to jump to after closing current CurrentTabIndex--; // Close Selected Tab TabPage ThisTab = tc.SelectedTab; ThisTab.Hide(); tc.TabPages.Remove(ThisTab); tc.SelectedIndex = CurrentTabIndex; // select the previous tab after closing current }
public Control TabControl(Control panel, string formName) { System.Windows.Forms.TabControl tabControl = (TabControl)panel; UserMaster formManager = GlobalPermission.UserPermission.FirstOrDefault(a => a.FormName == formName); List <Control> button = panel.Controls.OfType <Control>().ToList(); try { foreach (Control control in button) { TabPage tabPage = (TabPage)control; if (control.Tag != null) { if (control.Tag.ToString() == "1") { if (formManager.insertPermission) { tabPage.Show(); } else { tabPage.Hide(); } } } else { tabControl.TabPages.Remove(tabPage); } } } catch (Exception) { } return(tabControl); }
protected virtual void DeselectPage(TabPage page) { page.Selected = false; // Hide any associated control if (page.Control != null) { // Should we remember which control had focus when leaving? if (_recordFocus) { // Record current focus location on Control if (page.Control.ContainsFocus) page.StartFocus = FindFocus(page.Control); else page.StartFocus = null; } page.Control.Hide(); } else { // Should we remember which control had focus when leaving? if (_recordFocus) { // Record current focus location on Control if (page.ContainsFocus) page.StartFocus = FindFocus(page); else page.StartFocus = null; } page.Hide(); } }
protected virtual void AddTabPage(TabPage page) { // Has not been shown for the first time yet page.Shown = false; // Add user supplied control if (page.Control != null) { Form controlIsForm = page.Control as Form; page.Control.Hide(); // Adding a Form takes extra effort if (controlIsForm == null) { // Monitor focus changes on the Control page.Control.GotFocus += new EventHandler(OnPageEnter); page.Control.LostFocus += new EventHandler(OnPageLeave); page.Control.MouseEnter += new EventHandler(OnPageMouseEnter); page.Control.MouseLeave += new EventHandler(OnPageMouseLeave); // Must fill the entire hosting panel it is on page.Control.Dock = DockStyle.None; // Set correct size page.Control.Location = new Point(0,0); page.Control.Size = _hostPanel.Size; _hostPanel.Controls.Add(page.Control); } else { // Monitor activation changes on the TabPage controlIsForm.Activated += new EventHandler(OnPageEnter); controlIsForm.Deactivate += new EventHandler(OnPageLeave); controlIsForm.MouseEnter += new EventHandler(OnPageMouseEnter); controlIsForm.MouseLeave += new EventHandler(OnPageMouseLeave); // Have to ensure the Form is not a top level form controlIsForm.TopLevel = false; // We are the new parent of this form controlIsForm.Parent = _hostPanel; // To prevent user resizing the form manually and prevent // the caption bar appearing, we use the 'None' border style. controlIsForm.FormBorderStyle = FormBorderStyle.None; // Must fill the entire hosting panel it is on controlIsForm.Dock = DockStyle.None; // Set correct size controlIsForm.Location = new Point(0,0); controlIsForm.Size = _hostPanel.Size; } // Need to monitor when the Form/Panel is clicked if ((page.Control is Form) || (page.Control is Panel)) page.Control.MouseDown += new MouseEventHandler(OnPageMouseDown); RecursiveMonitor(page.Control, true); } else { page.Hide(); // Monitor focus changes on the TabPage page.GotFocus += new EventHandler(OnPageEnter); page.LostFocus += new EventHandler(OnPageLeave); page.MouseEnter += new EventHandler(OnPageMouseEnter); page.MouseLeave += new EventHandler(OnPageMouseLeave); // Must fill the entire hosting panel it is on page.Dock = DockStyle.None; // Need to monitor when the Panel is clicked page.MouseDown += new MouseEventHandler(OnPageMouseDown); RecursiveMonitor(page, true); // Set correct size page.Location = new Point(0,0); page.Size = _hostPanel.Size; // Add the TabPage itself instead _hostPanel.Controls.Add(page); } }
/// <summary>Hide/Remove Tab from TabControl</summary> /// <param name="tc">TabControl Name</param> /// <param name="tp">TabPage Name</param> public void Hide_Tab(TabControl tc, TabPage tp) { tp.Hide(); tc.TabPages.Remove(tp); }