private static void TabControl_OnMouseDown(object sender, MouseEventArgs e) { //Check all the tab to determind which tab that has mouse click fall into. foreach (TabPage tabPage in TabControl.TabPages) { //get the area of tab Rectangle tabRect = TabControl.GetTabRect(TabControl.TabPages.IndexOf(tabPage)); //get the area of the "x" image Rectangle imageXRect = new Rectangle(tabRect.Right - tabRect.Height, tabRect.Top, tabRect.Height, tabRect.Height); //Remove if (imageXRect.Contains(e.Location)) { //Safe close if ((CurrentTextArea.requiresSaving == 1) && (Dialog.ShowSafeCloseTabDialog(tabPage) == "Cancel")) { break; } //When we close the unselected tab, it will be automatically selected //So we need reset to the previous selected tab. //Check whether the previous selected tab is existing if (PreviousSelectedTabpage != null && TabControl.TabPages.Contains(PreviousSelectedTabpage)) { TabControl.SelectedTab = PreviousSelectedTabpage; } else { //if not, set the next selected tab to the nearest tab if (TabControl.SelectedIndex == 0) { TabControl.SelectedIndex = 1; } else { TabControl.SelectedIndex -= 1; } } //remove tabpage info in listOfTabPageInfo RemoveTabPageInfo(tabPage); //remove tab page TabControl.TabPages.Remove(tabPage); break; } } if (TabControl.TabPages.Count > 0) { CurrentTextArea.Focus(); } }
private void closeToolStripMenuItem_Click(object sender, EventArgs e) { if (tabControl.TabPages.Count > 0) { //Show SaveDialog if (TabControlMethods.CurrentTextArea.requiresSaving == 1) { string result = Dialog.ShowSafeCloseTabDialog(tabControl.SelectedTab); if (result == "Cancel") { return; } } //Choose the selected tab to remove TabPage tabToRemove = tabControl.SelectedTab; if (tabControl.SelectedIndex != 0) { //set the selectedtab to the first tab page tabControl.SelectedIndex = tabControl.SelectedIndex - 1; } //if the tab we are about to remove is the first tab, just simply set selectedtab to 1 else { tabControl.SelectedIndex = tabControl.SelectedIndex + 1; } //remove app info TabControlMethods.RemoveTabPageInfo(tabToRemove); //remove tab tabControl.TabPages.Remove(tabToRemove); if (tabControl.TabPages.Count > 0) { TabControlMethods.CurrentTextArea.Focus(); } } }
private void closeAllToolStripMenuItem_Click(object sender, EventArgs e) { //remove all the tab except the selected Tab foreach (TabPage tabPage in tabControl.TabPages) { if (tabPage != tabControl.SelectedTab) { string result = Dialog.ShowSafeCloseTabDialog(tabPage); if (TabControlMethods.CurrentTextArea.requiresSaving == 1 && result == "Cancel") { return; } ////Delete tab status //TabControlMethods.RemoveTabPageStatus(tabPage); //Remove tab Page tabControl.TabPages.Remove(tabPage); } } }
public static void CloseCurrentTabPage() { if (IsEmpty()) { return; } TabPage currentTab = TabControl.SelectedTab; if ((CurrentTextArea.requiresSaving == 1) && (Dialog.ShowSafeCloseTabDialog(currentTab) == "Cancel")) { } //Set the new SelectedTab if (PreviousSelectedTabpage != null && TabControl.TabPages.Contains(PreviousSelectedTabpage)) { TabControl.SelectedTab = PreviousSelectedTabpage; } else { //if not, set the next selected tab to the nearest tab if (TabControl.SelectedIndex == 0) { TabControl.SelectedIndex = 1; } else { TabControl.SelectedIndex -= 1; } } //remove tabpage info in listOfTabPageInfo RemoveTabPageInfo(currentTab); //remove tab page TabControl.TabPages.Remove(currentTab); }