Ejemplo n.º 1
0
        private void newTabToolStripMenuItem_Click(object sender, EventArgs e)
        {
            newControls                 = new MiscControls();
            newControls.Dock            = DockStyle.Fill;
            this.newControls.ParentForm = this;
            TabPage newPage = new TabPage("New Tab " + tabNumber.ToString());

            newPage.Controls.Add(newControls);
            this.tab1.TabPages.Add(newPage);
            tabNumber++;
        }
Ejemplo n.º 2
0
        private void Main_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && (e.KeyCode == Keys.T))
            {
                newControls                 = new MiscControls();
                newControls.Dock            = DockStyle.Fill;
                this.newControls.ParentForm = this;
                TabPage newPage = new TabPage("New Tab");
                newPage.Controls.Add(newControls);
                this.tab1.TabPages.Add(newPage);
            }

            if (e.Control && (e.KeyCode == Keys.W))
            {
                this.tab1.TabPages.RemoveAt(this.tab1.SelectedIndex);
            }
        }
Ejemplo n.º 3
0
        private void tab1_MouseDown(object sender, MouseEventArgs e)
        {
            //Add new tab or delete a tab
            var lastIndex = this.tab1.TabCount - 1;

            if (this.tab1.GetTabRect(lastIndex).Contains(e.Location))
            {
                newControls                 = new MiscControls();
                newControls.Dock            = DockStyle.Fill;
                this.newControls.ParentForm = this;
                TabPage newPage = new TabPage("New Tab " + tabNumber.ToString());
                newPage.Controls.Add(newControls);
                this.tab1.TabPages.Add(newPage);
                //this.tab1.TabPages.Insert(lastIndex, "New Tab");
                this.tab1.SelectedIndex = lastIndex;
                tabNumber++;
            }
            else
            {
                for (int i = 0; i < this.tab1.TabPages.Count; i++)
                {
                    Rectangle r = tab1.GetTabRect(i);
                    //Getting the position of the "x" mark.
                    Rectangle closeButton = new Rectangle(r.Right - 15, r.Top + 4, 9, 7);
                    if (closeButton.Contains(e.Location))
                    {
                        this.tab1.TabPages.RemoveAt(i);
                        break;
                    }
                }
            }

            //Drag and drop tabs
            //Store clicked tab
            TabControl tc          = (TabControl)sender;
            int        hover_index = this.getHoverTabIndex(tc);

            if (hover_index >= 0)
            {
                tc.Tag = tc.TabPages[hover_index];
            }
        }