public partial class ExtendedTabControl : TabControl { public ExtendedTabControl() { InitializeComponent(); } }
public override Rectangle DisplayRectangle { get { if (DesignMode || style == ExtendedTabControlStyle.TabControl) { return base.DisplayRectangle; } else { if (Width != size.Width || Height != size.Height) { size.Width = Width; size.Height = Height; rect = Rectangle.Empty; } if (rect == Rectangle.Empty) rect = new Rectangle(0, 0, Width, Height); return rect; } } }
protected override void CreateHandle() { base.CreateHandle(); if (!DesignMode && !(this.Parent == tableLayoutPanel)) { System.Windows.Forms.Control.ControlCollection col = this.Parent.Controls; for (int i = 0; i < col.Count; ++i) { if (this == col[i]) { col.Add(this.tableLayoutPanel); col.SetChildIndex(this.tableLayoutPanel, i); col.Remove(this); this.tableLayoutPanel.Controls.Add(this, 0, 1); break; } } foreach (TabPage tp in Controls) { tp.Padding = padding; tp.Margin = padding; } this.tableLayoutPanel.Padding = padding; this.tableLayoutPanel.Margin = padding; this.tableLayoutPanel.Dock = this.Dock; this.Dock = DockStyle.Fill; Synchronize(); if (defaultTab >= ToolStripButtonCollection.Count) defaultTab = 0; if (0 != ToolStripButtonCollection.Count) Update(defaultTab); } }
private void Synchronize() { ToolStripButtonCollection.Clear(); ToolStripSeparatorCollection.Clear(); int Index = 0; foreach (TabPage tp in this.TabPages) { Index = AddNewButton(tp, Index); } }
private void Update(ToolStripButton tsb) { if (null == tsb) return; topToolStrip.Items.Clear(); bottomToolStrip.Items.Clear(); int MaxBottomSize = bottomToolStrip.GripStyle == ToolStripGripStyle.Visible ? bottomToolStrip.GripRectangle.Height + bottomToolStrip.GripMargin.Size.Height : 0; int MaxTopSize = topToolStrip.GripStyle == ToolStripGripStyle.Visible ? topToolStrip.GripRectangle.Height + topToolStrip.GripMargin.Size.Height : 0; if (style != ExtendedTabControlStyle.TabControl) { bool FirstBottom = true; bool FirstTop = true; int i = 0; foreach (ToolStripButton btn in ToolStripButtonCollection) { btn.Checked = false; if (((int)btn.Tag) > ((int)tsb.Tag) || style == ExtendedTabControlStyle.Outlook) { if (!FirstBottom) { ToolStripSeparator toolStripSeparator = ToolStripSeparatorCollection[i]; bottomToolStrip.Items.Add(toolStripSeparator); MaxBottomSize += toolStripSeparator.Bounds.Height; } FirstBottom = false; bottomToolStrip.Items.Add(btn); MaxBottomSize += btn.Bounds.Height + btn.Padding.Size.Height; } else { if (!FirstTop) { ToolStripSeparator toolStripSeparator = ToolStripSeparatorCollection[i]; topToolStrip.Items.Add(toolStripSeparator); MaxTopSize += toolStripSeparator.Bounds.Height; } FirstTop = false; topToolStrip.Items.Add(btn); MaxTopSize += btn.Bounds.Height + btn.Padding.Size.Height; } ++i; } } tableLayoutPanel.RowStyles[0].Height = MaxTopSize; tableLayoutPanel.RowStyles[2].Height = MaxBottomSize; tsb.Checked = true; SelectedIndex = (int)tsb.Tag; }