예제 #1
0
        internal static void HideTabPage(MogMainForm main, ToolStripMenuItem removeItem)
        {
            TabControl tabControl = main.MOGTabControl;
            TabPage    current    = null;

            // Find the active visible page
            foreach (TabPage page in tabControl.TabPages)
            {
                if (string.Compare(page.Text, removeItem.Text, true) == 0)
                {
                    current = page;
                    break;
                }
            }

            // Do we have one?
            if (current != null)
            {
                // Add it to the hidden container
                mHiddenPages.TabPages.Add(current);

                // Save its current tab position that is saved in the tag of the tabPage
                removeItem.Tag = Convert.ToInt32(current.Tag);

                // Also set the tab name as the menuItem name so that we can look up the tab name by key using the menuItem name
                removeItem.Name = current.Name;

                // Remove the page
                tabControl.TabPages.Remove(current);
                tabControl.Refresh();

                // Hide our associated view menu item
                main.MOG_TabControl_HideViewTabMenuItem(current, false);
            }

            // Ok, we are hidden
            removeItem.Checked = false;
        }
예제 #2
0
        internal static void ShowTabPage(MogMainForm main, ToolStripMenuItem showItem)
        {
            TabControl tabControl = main.MOGTabControl;

            // Try and get the hidden page from our temp container by key
            TabPage page = mHiddenPages.TabPages[showItem.Name];

            if (page != null)
            {
                // Get the tab index of the hidden page
                int index = (int)showItem.Tag;

                // Do we currently have ANY pages?
                if (tabControl.TabPages.Count > 0)
                {
                    // Is the index for this page larger than our current number of pages?
                    if (index >= tabControl.TabPages.Count)
                    {
                        // Get the last visible pages prefered tab position
                        int    lastIndex = 0;
                        int    x         = 1;
                        string tag       = tabControl.TabPages[tabControl.TabPages.Count - 1].Tag as string;

                        while (true)
                        {
                            try
                            {
                                // Is this a web tab?
                                lastIndex = Convert.ToInt32(tag);
                                break;
                            }
                            catch
                            {
                                x++;
                                if (tabControl.TabPages.Count >= tabControl.TabPages.Count - x && tabControl.TabPages.Count - x > 0)
                                {
                                    // Then try the next tab back
                                    tag = tabControl.TabPages[tabControl.TabPages.Count - x].Tag as string;
                                }
                                else
                                {
                                    // We are out of tabs, so lets put it at the end
                                    lastIndex = index + 1;
                                    break;
                                }
                            }
                        }

                        // Is our current page position want to be after the last tabs position?
                        if (index > lastIndex)
                        {
                            // Then add it
                            tabControl.TabPages.Add(page);
                        }
                        else
                        {
                            // Then instert it
                            tabControl.TabPages.Insert(tabControl.TabPages.Count - 1, page);
                        }
                    }
                    else
                    {
                        // Then insert it
                        tabControl.TabPages.Insert(index, page);
                    }
                }
                else
                {
                    // Then add it
                    tabControl.TabPages.Add(page);

                    // Single pages need to be reInitialized
                    main.InitializeMainTabPage(page);
                }

                // Now remove this newly added page from our temp hidden container
                mHiddenPages.TabPages.Remove(page);

                // Ok we should be checked
                showItem.Checked = true;

                // Hide our associated view menu item
                main.MOG_TabControl_HideViewTabMenuItem(page, true);
            }
        }