//modify current tab' name //add a new tab private void AddTab(Tabcontent tc) { NewTabPage Page; TableLayoutPanel layoutPanel = new TableLayoutPanel(); layoutPanel.RowCount = 4; layoutPanel.ColumnCount = 8; layoutPanel.Dock = DockStyle.Fill; //tc has no buttons,add a empty page if (tc.tabname == "") { Page = new NewTabPage(); Page.Name = "Page" + _tabindex.ToString(); Page.Text = "tabPage" + _tabindex.ToString(); Page.TabIndex = _tabindex; Page.Controls.Add(layoutPanel); this.tabControl1.Controls.Add(Page); //layout button //int x = 8, y = 10; for (int i = 0; i != 32; i++) { TabButton tb = new TabButton(); tb._index = i; tb.Dock = DockStyle.Fill; toolTip1.SetToolTip(tb, tb.Text); /*Page.Controls.Add(tb); tb.Location = new System.Drawing.Point(x, y); x = x + tb.Width + 7; if (x + tb.Width > Page.Width) { x = 8; y = y + tb.Height + 6; }*/ for (int k = 0; k < layoutPanel.RowCount; k++) { layoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); for (int j = 0; j < layoutPanel.ColumnCount; j++) { layoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); layoutPanel.Controls.Add(tb); } } tb.Click += new System.EventHandler(command_button_Click); tb.MouseDown += new MouseEventHandler(command_button_MouseDown); } } //tc has buttons else { Page = new NewTabPage(); Page.Name = tc.tabname; Page.Text = tc.tabname; Page.TabIndex = _tabindex; Page.Controls.Add(layoutPanel); this.tabControl1.Controls.Add(Page); //layout button //int x = 8, y = 10; for (int i = 0; i != 32; i++) { TabButton tb = new TabButton(); tb._data = tc.buttons[i].data; tb._index = i; tb.Name = tc.buttons[i].btnname; tb.Text = tc.buttons[i].btnname; tb.Dock = DockStyle.Fill; toolTip1.SetToolTip(tb, tb.Text); /*Page.Controls.Add(tb); tb.Location = new System.Drawing.Point(x, y); x = x + tb.Width + 7; if (x + tb.Width > Page.Width) { x = 8; y = y + tb.Height + 6; }*/ for (int k = 0; k < layoutPanel.RowCount; k++) { layoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 50F)); for (int j = 0; j < layoutPanel.ColumnCount; j++) { layoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); layoutPanel.Controls.Add(tb); } } tb.Click += new System.EventHandler(command_button_Click); tb.MouseDown += new MouseEventHandler(command_button_MouseDown); } } #region 三种设置某个选项卡为当前选项卡的方法 //this.tabControl1.SelectedIndex = index; //this.tabControl1.SelectedTab = Page; //this.tabControl1.SelectTab("Page" + index.ToString()); #endregion _tabindex++; }
private void Newtab_Click(object sender, EventArgs e) { NewTabPage Page; //tc has no buttons,add a empty page Page = new NewTabPage(); Page.Name = "Page" + _tabindex.ToString(); Page.Text = "tabPage" + _tabindex.ToString(); Page.TabIndex = _tabindex; TableLayoutPanel layoutPanel = new TableLayoutPanel(); layoutPanel.RowCount = 4; layoutPanel.ColumnCount = 8; layoutPanel.Dock = DockStyle.Fill; Page.Controls.Add(layoutPanel); this.tabControl1.Controls.Add(Page); //layout button //int x = 8, y = 10; for (int i = 0; i != 32; i++) { TabButton tb = new TabButton(); tb._index = i; toolTip1.SetToolTip(tb, tb.Text); tb.Dock = DockStyle.Fill; for (int k = 0; k < layoutPanel.RowCount; k++) { layoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); for (int j = 0; j < layoutPanel.ColumnCount; j++) { layoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); layoutPanel.Controls.Add(tb); } } tb.Click += new System.EventHandler(command_button_Click); tb.MouseDown += new MouseEventHandler(command_button_MouseDown); } }