Exemple #1
0
        /// <summary>
        /// close selected tab
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void closeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tabControl.TabPages.Count > 1) //we don't remove tab page when tabControl has only one tab page
            {
                //we can use this one line of code below to easily remove selected tab page but it causes flinking
                // tabControl.TabPages.Remove(tabControl.SelectedTab);

                //Show SaveDialog
                string result = DiaLogClass.ShowSafeCloseTabDialog(tabControl.SelectedTab);

                if (result == "Cancel")
                {
                    return;
                }

                //Delete the selected tab page status
                TabControlClass.RemoveTabPageStatus(tabControl.SelectedTab);

                //that's the reason why use the number lines of code below
                //somehow if we set the tab page we are about to remove to another one (in this case we are about to remove selected tab page),
                //it doesn't cause the flinking
                TabPage tabToRemove = tabControl.SelectedTab;
                if (tabControl.SelectedIndex != 0)
                {
                    //set the selectedtab to the first tab page
                    tabControl.SelectedIndex = tabControl.SelectedIndex - 1;
                }
                else //if the tab we are about to remove is the first tab, just simply set selectedtab to 1
                {
                    tabControl.SelectedTab = tabControl.TabPages[1];
                }
                //remove tab
                tabControl.TabPages.Remove(tabToRemove);
            }
        }
Exemple #2
0
        /// <summary>
        /// close all tap except selected tab
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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 = DiaLogClass.ShowSafeCloseTabDialog(tabPage);
                    if (result == "Cancel")
                    {
                        return;
                    }

                    //Delete tab status
                    TabControlClass.RemoveTabPageStatus(tabPage);

                    //Remove tab Page
                    tabControl.TabPages.Remove(tabPage);
                }
            }
        }