protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { if (renderer is ToolStripProfessionalRenderer) { Color back = PluginBase.MainForm.GetThemeColor("ToolStripItem.BackColor"); Color border = PluginBase.MainForm.GetThemeColor("ToolStripItem.BorderColor"); if (e.Item.Selected || ((ToolStripButton)e.Item).Checked) { Rectangle rect = new Rectangle(0, 0, e.Item.Width, e.Item.Height); Rectangle rect2 = new Rectangle(1, 1, e.Item.Width - 2, e.Item.Height - 2); LinearGradientBrush b = new LinearGradientBrush(rect, back == Color.Empty ? DockDrawHelper.ColorSelectedBG_White : back, back == Color.Empty ? DockDrawHelper.ColorSelectedBG_Blue : back, LinearGradientMode.Vertical); e.Graphics.FillRectangle(b, rect); Rectangle rect3 = new Rectangle(rect2.Left - 1, rect2.Top - 1, rect2.Width + 1, rect2.Height + 1); Rectangle rect4 = new Rectangle(rect3.Left + 1, rect3.Top + 1, rect3.Width - 2, rect3.Height - 2); e.Graphics.DrawRectangle(new Pen(border == Color.Empty ? DockDrawHelper.ColorSelectedBG_Border : border), rect3); e.Graphics.DrawRectangle(new Pen(back == Color.Empty ? DockDrawHelper.ColorSelectedBG_White : back), rect4); } if (e.Item.Pressed) { Rectangle rect = new Rectangle(1, 1, e.Item.Width - 2, e.Item.Height - 2); LinearGradientBrush b = new LinearGradientBrush(rect, back == Color.Empty ? DockDrawHelper.ColorSelectedBG_White : back, back == Color.Empty ? DockDrawHelper.ColorSelectedBG_Blue : back, LinearGradientMode.Vertical); e.Graphics.FillRectangle(b, rect); Rectangle rect2 = new Rectangle(rect.Left - 1, rect.Top - 1, rect.Width + 1, rect.Height + 1); e.Graphics.DrawRectangle(new Pen(border == Color.Empty ? DockDrawHelper.ColorSelectedBG_Border : border), rect2); } } else { renderer.DrawButtonBackground(e); } }
protected override void OnPaint(PaintEventArgs e) { if (base.Owner != null) { ToolStripRenderer renderer = base.Renderer; renderer.DrawButtonBackground(new ToolStripItemRenderEventArgs(e.Graphics, this)); if ((this.DisplayStyle & ToolStripItemDisplayStyle.Image) == ToolStripItemDisplayStyle.Image) { ToolStripItemImageRenderEventArgs args = new ToolStripItemImageRenderEventArgs(e.Graphics, this, base.InternalLayout.ImageRectangle) { ShiftOnPress = true }; renderer.DrawItemImage(args); } if ((this.DisplayStyle & ToolStripItemDisplayStyle.Text) == ToolStripItemDisplayStyle.Text) { renderer.DrawItemText(new ToolStripItemTextRenderEventArgs(e.Graphics, this, this.Text, base.InternalLayout.TextRectangle, this.ForeColor, this.Font, base.InternalLayout.TextFormat)); } } }
/// <include file='doc\ToolStripButton.uex' path='docs/doc[@for="ToolStripButton.OnPaint"]/*' /> /// <devdoc> /// Inheriting classes should override this method to handle this event. /// </devdoc> protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { if (this.Owner != null) { ToolStripRenderer renderer = this.Renderer; renderer.DrawButtonBackground(new ToolStripItemRenderEventArgs(e.Graphics, this)); if ((DisplayStyle & ToolStripItemDisplayStyle.Image) == ToolStripItemDisplayStyle.Image) { ToolStripItemImageRenderEventArgs rea = new ToolStripItemImageRenderEventArgs(e.Graphics, this, InternalLayout.ImageRectangle); rea.ShiftOnPress = true; renderer.DrawItemImage(rea); } if ((DisplayStyle & ToolStripItemDisplayStyle.Text) == ToolStripItemDisplayStyle.Text) { renderer.DrawItemText(new ToolStripItemTextRenderEventArgs(e.Graphics, this, this.Text, InternalLayout.TextRectangle, this.ForeColor, this.Font, InternalLayout.TextFormat)); } } }
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { if (renderer is ToolStripProfessionalRenderer) { Boolean isOver = false; Color back = GetThemeColor("ToolStripItem.BackColor"); Color border = GetThemeColor("ToolStripItem.BorderColor"); Color active = GetThemeColor("ToolStripMenu.DropDownBorderColor"); if (e.Item is ToolStripButton) { ToolStripButton button = e.Item as ToolStripButton; Rectangle bBounds = button.Owner.RectangleToScreen(button.Bounds); isOver = bBounds.Contains(Control.MousePosition); } if (e.Item.Selected || ((ToolStripButton)e.Item).Checked || (isOver && e.Item.Enabled)) { Rectangle rect = new Rectangle(0, 0, e.Item.Width, e.Item.Height); Rectangle rect2 = new Rectangle(1, 1, e.Item.Width - 2, e.Item.Height - 2); LinearGradientBrush b = new LinearGradientBrush(rect, back == Color.Empty ? DockDrawHelper.ColorSelectedBG_White : back, back == Color.Empty ? DockDrawHelper.ColorSelectedBG_Blue : back, LinearGradientMode.Vertical); e.Graphics.FillRectangle(b, rect); Rectangle rect3 = new Rectangle(rect2.Left - 1, rect2.Top - 1, rect2.Width + 1, rect2.Height + 1); Rectangle rect4 = new Rectangle(rect3.Left + 1, rect3.Top + 1, rect3.Width - 2, rect3.Height - 2); e.Graphics.DrawRectangle(new Pen(border == Color.Empty ? DockDrawHelper.ColorSelectedBG_Border : border), rect3); e.Graphics.DrawRectangle(new Pen(back == Color.Empty ? DockDrawHelper.ColorSelectedBG_White : back), rect4); } if (e.Item.Pressed) { Rectangle rect = new Rectangle(1, 1, e.Item.Width - 2, e.Item.Height - 2); LinearGradientBrush b = new LinearGradientBrush(rect, back == Color.Empty ? DockDrawHelper.ColorSelectedBG_White : back, back == Color.Empty ? DockDrawHelper.ColorSelectedBG_Blue : back, LinearGradientMode.Vertical); e.Graphics.FillRectangle(b, rect); Rectangle rect2 = new Rectangle(rect.Left - 1, rect.Top - 1, rect.Width + 1, rect.Height + 1); e.Graphics.DrawRectangle(new Pen(active == Color.Empty ? DockDrawHelper.ColorSelectedBG_Border : active), rect2); } } else { renderer.DrawButtonBackground(e); } }
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { renderer.DrawButtonBackground(e); }
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { Graphics g = e.Graphics; g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; //todo:背景渐变色,边框色, 关闭按钮 TabStrip tabs = e.ToolStrip as TabStrip; TabStripButton tab = e.Item as TabStripButton; if (tabs == null || tab == null) { if (_currentRenderer != null) { _currentRenderer.DrawButtonBackground(e); } else { base.OnRenderButtonBackground(e); } return; } bool selected = tab.Checked; bool hovered = tab.Selected; int top = 0; int left = 0; int width = tab.Bounds.Width - 1; int height = tab.Bounds.Height - 1; Rectangle drawBorder; if (UseVS) { #region Visual Style if (tabs.Orientation == Orientation.Horizontal) { if (!selected) { top = selOffset; height -= (selOffset - 1); } else { top = 1; } drawBorder = new Rectangle(0, 0, width, height); } else { if (!selected) { left = selOffset; width -= (selOffset - 1); } else { left = 1; } drawBorder = new Rectangle(0, 0, height, width); } using (Bitmap b = new Bitmap(drawBorder.Width, drawBorder.Height)) { VisualStyleElement el = VisualStyleElement.Tab.TabItem.Normal; if (selected) { el = VisualStyleElement.Tab.TabItem.Pressed; } if (hovered) { el = VisualStyleElement.Tab.TabItem.Hot; } if (!tab.Enabled) { el = VisualStyleElement.Tab.TabItem.Disabled; } if (!selected) { } else if (hovered) { //drawBorder.Width++; } else { drawBorder.Height++; } using (Graphics gr = Graphics.FromImage(b)) { VisualStyleRenderer rndr = new VisualStyleRenderer(el); rndr.DrawBackground(gr, drawBorder); if (tabs.Orientation == Orientation.Vertical) { if (Mirrored) { b.RotateFlip(RotateFlipType.Rotate270FlipXY); } else { b.RotateFlip(RotateFlipType.Rotate270FlipNone); } } else { if (Mirrored) { b.RotateFlip(RotateFlipType.RotateNoneFlipY); } } if (Mirrored) { left = tab.Bounds.Width - b.Width - left; top = tab.Bounds.Height - b.Height - top; } g.DrawImage(b, left, top); } } #endregion } // UseVS == true END else { if (tabs.Orientation == Orientation.Horizontal) { if (!selected) { top = selOffset; height -= (selOffset - 1); } else { top = 1; } if (Mirrored) { left = 1; top = 0; } else { top++; } width--; } else { if (!selected) { left = selOffset; width--; } else { left = 1; } if (Mirrored) { left = 0; top = 1; } } height--; drawBorder = new Rectangle(left, top, width, height); using (GraphicsPath gp = new GraphicsPath()) { if (Mirrored && tabs.Orientation == Orientation.Horizontal) { gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Left, drawBorder.Bottom - 2); gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90); gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right - 2, drawBorder.Bottom); gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90); gp.AddLine(drawBorder.Right, drawBorder.Bottom - 2, drawBorder.Right, drawBorder.Top); } else if (!Mirrored && tabs.Orientation == Orientation.Horizontal) { gp.AddLine(drawBorder.Left, drawBorder.Bottom, drawBorder.Left, drawBorder.Top + 2); gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90); gp.AddLine(drawBorder.Left + 2, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top); gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90); gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom); } else if (Mirrored && tabs.Orientation == Orientation.Vertical) { gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top); gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90); gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom - 2); gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90); gp.AddLine(drawBorder.Right - 2, drawBorder.Bottom, drawBorder.Left, drawBorder.Bottom); } else { gp.AddLine(drawBorder.Right, drawBorder.Top, drawBorder.Left + 2, drawBorder.Top); gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90); gp.AddLine(drawBorder.Left, drawBorder.Top + 2, drawBorder.Left, drawBorder.Bottom - 2); gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90); gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right, drawBorder.Bottom); } if (selected || hovered) { Color fill = (hovered) ? Color.WhiteSmoke : Color.White; if (_renderMode == ToolStripRenderMode.Professional) { fill = (hovered) ? ProfessionalColors.ButtonCheckedGradientBegin : ProfessionalColors.ButtonCheckedGradientEnd; using (LinearGradientBrush br = new LinearGradientBrush(tab.ContentRectangle, fill, ProfessionalColors.ButtonCheckedGradientMiddle, LinearGradientMode.Vertical)) { g.FillPath(br, gp); } } else { using (SolidBrush br = new SolidBrush(fill)) { g.FillPath(br, gp); } } } else { using (SolidBrush br = new SolidBrush(_inactivedTabBackColor)) { g.FillPath(br, gp); } } using (Pen p = new Pen((selected) ? ControlPaint.Dark(SystemColors.AppWorkspace) : SystemColors.AppWorkspace)) { g.DrawPath(p, gp); } } } // UseVS == false END }
protected override void OnRenderButtonBackground(System.Windows.Forms.ToolStripItemRenderEventArgs e) { System.Drawing.Rectangle rectangle1; System.Drawing.Graphics graphics1 = e.Graphics; Oranikle.Studio.Controls.CtrlTabStrip ctrlTabStrip = e.ToolStrip as Oranikle.Studio.Controls.CtrlTabStrip; Oranikle.Studio.Controls.CtrlTabStripButton ctrlTabStripButton = e.Item as Oranikle.Studio.Controls.CtrlTabStripButton; if ((ctrlTabStrip == null) || (ctrlTabStripButton == null)) { if (currentRenderer != null) { currentRenderer.DrawButtonBackground(e); return; } base.OnRenderButtonBackground(e); return; } bool flag1 = ctrlTabStripButton.Checked; bool flag2 = ctrlTabStripButton.Selected; int i1 = 0, i2 = 0; System.Drawing.Rectangle rectangle3 = ctrlTabStripButton.Bounds; int i3 = rectangle3.Width - 1; System.Drawing.Rectangle rectangle4 = ctrlTabStripButton.Bounds; int i4 = rectangle4.Height - 1; if (UseVS) { if (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Horizontal) { if (!flag1) { i1 = 2; i4--; } else { i1 = 1; } rectangle1 = new System.Drawing.Rectangle(0, 0, i3, i4); } else { if (!flag1) { i2 = 2; i3--; } else { i2 = 1; } rectangle1 = new System.Drawing.Rectangle(0, 0, i4, i3); } using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(rectangle1.Width, rectangle1.Height)) { System.Windows.Forms.VisualStyles.VisualStyleElement visualStyleElement = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Normal; if (flag1) { visualStyleElement = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Pressed; } if (flag2) { visualStyleElement = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Hot; } if (!ctrlTabStripButton.Enabled) { visualStyleElement = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Disabled; } if (!flag1 || flag2) { rectangle1.Width++; } else { rectangle1.Height++; } using (System.Drawing.Graphics graphics2 = System.Drawing.Graphics.FromImage(bitmap)) { System.Windows.Forms.VisualStyles.VisualStyleRenderer visualStyleRenderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(visualStyleElement); visualStyleRenderer.DrawBackground(graphics2, rectangle1); if (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Vertical) { if (Mirrored) { bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone); } else { bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone); } } else if (Mirrored) { bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX); } if (Mirrored) { System.Drawing.Rectangle rectangle5 = ctrlTabStripButton.Bounds; i2 = rectangle5.Width - bitmap.Width - i2; System.Drawing.Rectangle rectangle6 = ctrlTabStripButton.Bounds; i1 = rectangle6.Height - bitmap.Height - i1; } graphics1.DrawImage(bitmap, i2, i1); } return; } } if (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Horizontal) { if (!flag1) { i1 = ctrlTabStripButton.VerticalOffsetInactive; i4 -= ctrlTabStripButton.VerticalOffsetInactive - 1; } else { i1 = ctrlTabStripButton.VerticalOffset; } if (Mirrored) { i2 = 1; i1 = 0; } else { i1++; } i3--; } else { if (!flag1) { i2 = 2; i3--; } else { i2 = 1; } if (Mirrored) { i2 = 0; i1 = 1; } } i4--; rectangle1 = new System.Drawing.Rectangle(i2, i1, i3, i4); using (System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath()) { if (Mirrored && (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Horizontal)) { graphicsPath.AddLine(rectangle1.Left, rectangle1.Top, rectangle1.Left, rectangle1.Bottom - 2); graphicsPath.AddArc(rectangle1.Left, rectangle1.Bottom - 3, 2, 2, 90.0F, 90.0F); graphicsPath.AddLine(rectangle1.Left + 2, rectangle1.Bottom, rectangle1.Right - 2, rectangle1.Bottom); graphicsPath.AddArc(rectangle1.Right - 2, rectangle1.Bottom - 3, 2, 2, 0.0F, 90.0F); graphicsPath.AddLine(rectangle1.Right, rectangle1.Bottom - 2, rectangle1.Right, rectangle1.Top); } else if (!Mirrored && (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Horizontal)) { int i5 = 1, i6 = 3; graphicsPath.AddLine(rectangle1.Left, rectangle1.Bottom, rectangle1.Left, rectangle1.Top + i6); graphicsPath.AddArc(rectangle1.Left, rectangle1.Top + i6 - 1, i6, i6, 180.0F, 90.0F); graphicsPath.AddLine(rectangle1.Left + i6, rectangle1.Top, rectangle1.Right - i6 - i5, rectangle1.Top); graphicsPath.AddArc(rectangle1.Right - i6 - i5, rectangle1.Top + i6 - 1, i6, i6, 270.0F, 90.0F); graphicsPath.AddLine(rectangle1.Right - i5, rectangle1.Top + i6, rectangle1.Right - i5, rectangle1.Bottom); } else if (Mirrored && (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Vertical)) { graphicsPath.AddLine(rectangle1.Left, rectangle1.Top, rectangle1.Right - 2, rectangle1.Top); graphicsPath.AddArc(rectangle1.Right - 2, rectangle1.Top + 1, 2, 2, 270.0F, 90.0F); graphicsPath.AddLine(rectangle1.Right, rectangle1.Top + 2, rectangle1.Right, rectangle1.Bottom - 2); graphicsPath.AddArc(rectangle1.Right - 2, rectangle1.Bottom - 3, 2, 2, 0.0F, 90.0F); graphicsPath.AddLine(rectangle1.Right - 2, rectangle1.Bottom, rectangle1.Left, rectangle1.Bottom); } else { graphicsPath.AddLine(rectangle1.Right, rectangle1.Top, rectangle1.Left + 2, rectangle1.Top); graphicsPath.AddArc(rectangle1.Left, rectangle1.Top + 1, 2, 2, 180.0F, 90.0F); graphicsPath.AddLine(rectangle1.Left, rectangle1.Top + 2, rectangle1.Left, rectangle1.Bottom - 2); graphicsPath.AddArc(rectangle1.Left, rectangle1.Bottom - 3, 2, 2, 90.0F, 90.0F); graphicsPath.AddLine(rectangle1.Left + 2, rectangle1.Bottom, rectangle1.Right, rectangle1.Bottom); } System.Drawing.Color color1 = ctrlTabStripButton.BackColorInactive; if (flag1) { color1 = ctrlTabStripButton.BackColor; } else if (flag2) { color1 = ctrlTabStripButton.BackColorHot; } System.Drawing.Color color2 = ctrlTabStripButton.BackColor2Inactive; if (flag1) { color2 = ctrlTabStripButton.BackColor2; } else if (flag2) { color2 = ctrlTabStripButton.BackColor2Hot; } if (renderMode == System.Windows.Forms.ToolStripRenderMode.Professional) { color1 = flag2 ? System.Windows.Forms.ProfessionalColors.ButtonCheckedGradientBegin : System.Windows.Forms.ProfessionalColors.ButtonCheckedGradientEnd; using (System.Drawing.Drawing2D.LinearGradientBrush linearGradientBrush1 = new System.Drawing.Drawing2D.LinearGradientBrush(ctrlTabStripButton.ContentRectangle, color1, System.Windows.Forms.ProfessionalColors.ButtonCheckedGradientMiddle, System.Drawing.Drawing2D.LinearGradientMode.Vertical)) { graphics1.FillPath(linearGradientBrush1, graphicsPath); goto label_1; } } using (System.Drawing.Drawing2D.LinearGradientBrush linearGradientBrush2 = new System.Drawing.Drawing2D.LinearGradientBrush(ctrlTabStripButton.ContentRectangle, color1, color2, System.Drawing.Drawing2D.LinearGradientMode.Vertical)) { graphics1.FillPath(linearGradientBrush2, graphicsPath); } label_1: if (flag1) { using (System.Drawing.Pen pen1 = new System.Drawing.Pen(ctrlTabStripButton.BorderColor)) { graphics1.DrawPath(pen1, graphicsPath); goto label_2; } } if (flag2) { using (System.Drawing.Pen pen2 = new System.Drawing.Pen(ctrlTabStripButton.BorderColorHot)) { graphics1.DrawPath(pen2, graphicsPath); goto label_2; } } using (System.Drawing.Pen pen3 = new System.Drawing.Pen(ctrlTabStripButton.BorderColorInactive)) { graphics1.DrawPath(pen3, graphicsPath); } label_2: if (ctrlTabStripButton.ShowCloseButton) { System.Drawing.Image image = Oranikle.Studio.Controls.Properties.Resources.Icon_Close_Disabled_16; if (flag2) { image = Oranikle.Studio.Controls.Properties.Resources.Icon_Close_16; } System.Drawing.Rectangle rectangle2 = new System.Drawing.Rectangle(i2 + i3 - ctrlTabStripButton.CloseButtonHorizontalOffset, ctrlTabStripButton.CloseButtonVerticalOffset, 8, 8); graphics1.DrawImage(image, rectangle2); } } }