public RenameTextBox(Toolbox toolbox) { this._owner = toolbox; this.Visible = false; //this.BorderStyle = BorderStyle.None; toolbox.Controls.Add(this); }
/// <summary> /// Initializes a new instance of the <see cref="TabEventArgs"/> class. /// </summary> /// <param name="tab">A <see cref="Toolbox.Tab">Tab</see> object on which an event is raised.</param> public TabEventArgs(Toolbox.Tab tab) { if (tab == null) { throw new ArgumentNullException("tab"); } this._tab = tab; }
/// <summary> /// Draws the <see cref="Tab"/> on the <see cref="Toolbox"/>. /// </summary> /// <param name="e">A <see cref="PaintEventArgs"/> that contains the paint event data.</param> protected virtual void OnPaint(PaintEventArgs e) { Toolbox toolbox = this.Toolbox; if (toolbox == null) { return; } GraphicsPath tabPath = this.GetTabPath(); RectangleF tabRectangle = tabPath.GetBounds(); // Draw tab if (this.Selected) { using (Brush selBrush = new SolidBrush(toolbox.TabSelectColor)) { e.Graphics.FillPath(selBrush, tabPath); } using (Pen selPen = new Pen(toolbox.TabSelectBorderColor)) { e.Graphics.DrawRectangle(selPen, tabRectangle.Left, tabRectangle.Top, tabRectangle.Width - 1, tabRectangle.Height - 1); } } else if (toolbox.TabColorStyle != ColorStyle.None) { Color backColorStart; Color backColorEnd; switch (toolbox.TabColorStyle) { case ColorStyle.Lighter: backColorStart = ControlPaint.Light(toolbox.BackColorGradientStart, 0.001f); backColorEnd = ControlPaint.Light(toolbox.BackColorGradientEnd, 0.001f); break; case ColorStyle.Darker: backColorStart = ControlPaint.Dark(toolbox.BackColorGradientStart, 0.001f); backColorEnd = ControlPaint.Dark(toolbox.BackColorGradientEnd, 0.001f); break; default: backColorStart = Color.LightGray; backColorEnd = Color.Gray; break; } RectangleF gradientRectangle = tabRectangle; gradientRectangle.Inflate(1, 1); using ( Brush unselectedBrush = new LinearGradientBrush(gradientRectangle, backColorStart, backColorEnd, LinearGradientMode.Horizontal)) { e.Graphics.FillPath(unselectedBrush, tabPath); } } // Draw collapsed/expanded icon Point stateIconPosition = Point.Round(tabRectangle.Location); stateIconPosition.Y += (int)(tabRectangle.Height - _collapsed.Height) / 2; if (this.Opened) { e.Graphics.DrawImageUnscaled(_expanded, stateIconPosition); } else { e.Graphics.DrawImageUnscaled(_collapsed, stateIconPosition); } // Draw tab Text Brush textBrush = new SolidBrush(toolbox.ForeColor); SizeF textSize = e.Graphics.MeasureString(this.Text, toolbox.TabFont); RectangleF textRectangle = new RectangleF(tabRectangle.Left + _expanded.Width + Gap_IconFromText, tabRectangle.Top + (tabRectangle.Height - textSize.Height) / 2, tabRectangle.Width - _expanded.Width - Gap_IconFromText, textSize.Height); e.Graphics.DrawString(this.Text, toolbox.TabFont, textBrush, textRectangle, _tabCaptionFormat); this._height = (int)tabRectangle.Height; // Draw items if (this.Opened) { Point location = new Point((int)tabRectangle.Left + ((toolbox.DrawTabLevel) ? Gap_TabLevel : 0), (int)tabRectangle.Bottom); if (this.Items.Count == 0 && (!toolbox.AllowNestedTabs || this.Categories.Count == 0) && (!toolbox.ShowAll || !toolbox.ShowPointer)) { // Draw text ToolboxTabNoItemsText // Before and after this text goes empty line with height = Toolbox.ItemHeight string text = Resources.ToolboxTabNoItemsText; textSize = e.Graphics.MeasureString(text, toolbox.Font, this.Width - ((toolbox.DrawTabLevel) ? Gap_TabLevel : 0)); textRectangle = new RectangleF(location.X, location.Y + Gap_ItemBetween + toolbox.ItemHeight, textSize.Width, textSize.Height); e.Graphics.DrawString(text, toolbox.Font, textBrush, textRectangle, _tabEmptyTextFormat); location.Offset(0, (int)(2 * toolbox.ItemHeight + 2 * Gap_ItemBetween + textSize.Height)); } else { if (toolbox.AllowNestedTabs && this.Categories.Count > 0) { foreach (Tab tab in this.Categories) { if (tab.Visible || toolbox.ShowAll) { location.Offset(0, Gap_TabBetween); tab.InternalPaint(e, ref location); } } location.Offset(0, Gap_TabBetween); } if (toolbox.ShowPointer && (this.Items.Count > 0 || toolbox.ShowAll)) { location.Offset(0, Gap_ItemBetween); this.PointerItem.InternalPaint(e, location); location.Offset(0, toolbox.ItemHeight); } foreach (Item item in this.Items) { if (item.Visible || toolbox.ShowAll) { location.Offset(0, Gap_ItemBetween); item.InternalPaint(e, location); location.Offset(0, toolbox.ItemHeight); } } } this._height += (int)(location.Y - tabRectangle.Bottom); if (toolbox.DrawTabLevel) { using (Pen levelPen = new Pen(Color.Black, 1)) { e.Graphics.DrawLine(levelPen, tabRectangle.Left + Gap_TabLevel / 3f, tabRectangle.Bottom + Gap_TabBetween, tabRectangle.Left + Gap_TabLevel / 3f, location.Y - Gap_TabBetween); e.Graphics.DrawLine(levelPen, tabRectangle.Left + Gap_TabLevel / 3f, location.Y - Gap_TabBetween, tabRectangle.Left + Gap_TabLevel * 2 / 3f, location.Y - Gap_TabBetween); } } } }