protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs e) { ToolStrip toolStrip = e.ToolStrip; ToolStripSplitButton item = e.Item as ToolStripSplitButton; if (item != null) { Graphics graphics = e.Graphics; LinearGradientMode mode = (toolStrip.Orientation == Orientation.Horizontal) ? LinearGradientMode.Vertical : LinearGradientMode.Horizontal; Rectangle bounds = new Rectangle(Point.Empty, item.Size); new SmoothingModeGraphics(graphics); Color arrowColor = toolStrip.Enabled ? this.ColorTable.Fore : SystemColors.ControlDark; if (item.BackgroundImage != null) { Rectangle clipRect = item.Selected ? item.ContentRectangle : bounds; ControlPaintEx.DrawBackgroundImage(graphics, item.BackgroundImage, this.ColorTable.Back, item.BackgroundImageLayout, bounds, clipRect); } if (item.ButtonPressed) { if (this.ColorTable.BaseItemDown != null) { ImageDrawRect.DrawRect(graphics, (Bitmap)this.ColorTable.BaseItemDown, bounds, Rectangle.FromLTRB(this.ColorTable.BackRectangle.X, this.ColorTable.BackRectangle.Y, this.ColorTable.BackRectangle.Width, this.ColorTable.BackRectangle.Height), 1, 1); } else { Rectangle buttonBounds = item.ButtonBounds; Padding padding = (item.RightToLeft == RightToLeft.Yes) ? new Padding(0, 1, 1, 1) : new Padding(1, 1, 0, 1); buttonBounds = LayoutUtils.DeflateRect(buttonBounds, padding); RenderHelperStrip.RenderBackgroundInternal(graphics, bounds, this.ColorTable.BaseItemHover, this.ColorTable.BaseItemBorder, this.ColorTable.Back, this.ColorTable.BaseItemRadiusStyle, this.ColorTable.BaseItemRadius, this.ColorTable.BaseItemBorderShow, this.ColorTable.BaseItemAnamorphosis, mode); buttonBounds.Inflate(-1, -1); graphics.SetClip(buttonBounds); RenderHelperStrip.RenderBackgroundInternal(graphics, buttonBounds, this.ColorTable.BaseItemPressed, this.ColorTable.BaseItemBorder, this.ColorTable.Back, RoundStyle.Left, false, true, mode); graphics.ResetClip(); using (Pen pen = new Pen(this.ColorTable.BaseItemSplitter)) { graphics.DrawLine(pen, item.SplitterBounds.Left, item.SplitterBounds.Top, item.SplitterBounds.Left, item.SplitterBounds.Bottom); } } base.DrawArrow(new ToolStripArrowRenderEventArgs(graphics, item, item.DropDownButtonBounds, arrowColor, ArrowDirection.Down)); } else if (!item.Pressed && !item.DropDownButtonPressed) { if (item.Selected) { if (this.ColorTable.BaseItemMouse != null) { ImageDrawRect.DrawRect(graphics, (Bitmap)this.ColorTable.BaseItemMouse, bounds, Rectangle.FromLTRB(this.ColorTable.BackRectangle.X, this.ColorTable.BackRectangle.Y, this.ColorTable.BackRectangle.Width, this.ColorTable.BackRectangle.Height), 1, 1); } else { RenderHelperStrip.RenderBackgroundInternal(graphics, bounds, this.ColorTable.BaseItemHover, this.ColorTable.BaseItemBorder, this.ColorTable.Back, this.ColorTable.BaseItemRadiusStyle, this.ColorTable.BaseItemRadius, this.ColorTable.BaseItemBorderShow, this.ColorTable.BaseItemAnamorphosis, mode); using (Pen pen2 = new Pen(this.ColorTable.BaseItemSplitter)) { graphics.DrawLine(pen2, item.SplitterBounds.Left, item.SplitterBounds.Top, item.SplitterBounds.Left, item.SplitterBounds.Bottom); } } base.DrawArrow(new ToolStripArrowRenderEventArgs(graphics, item, item.DropDownButtonBounds, arrowColor, ArrowDirection.Down)); } else { base.DrawArrow(new ToolStripArrowRenderEventArgs(graphics, item, item.DropDownButtonBounds, arrowColor, ArrowDirection.Down)); } } else { if (this.ColorTable.BaseItemDown != null) { ImageDrawRect.DrawRect(graphics, (Bitmap)this.ColorTable.BaseItemDown, bounds, Rectangle.FromLTRB(this.ColorTable.BackRectangle.X, this.ColorTable.BackRectangle.Y, this.ColorTable.BackRectangle.Width, this.ColorTable.BackRectangle.Height), 1, 1); } else { RenderHelperStrip.RenderBackgroundInternal(graphics, bounds, this.ColorTable.BaseItemPressed, this.ColorTable.BaseItemBorder, this.ColorTable.Back, this.ColorTable.BaseItemRadiusStyle, this.ColorTable.BaseItemRadius, this.ColorTable.BaseItemBorderShow, this.ColorTable.BaseItemAnamorphosis, mode); } base.DrawArrow(new ToolStripArrowRenderEventArgs(graphics, item, item.DropDownButtonBounds, arrowColor, ArrowDirection.Down)); } } else { base.OnRenderSplitButtonBackground(e); } }
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { ToolStrip toolStrip = e.ToolStrip; ToolStripButton item = e.Item as ToolStripButton; Graphics graphics = e.Graphics; if (item == null) { return; } LinearGradientMode mode = (toolStrip.Orientation == Orientation.Horizontal) ? LinearGradientMode.Vertical : LinearGradientMode.Horizontal; SmoothingModeGraphics graphics2 = new SmoothingModeGraphics(graphics); Rectangle bounds = new Rectangle(Point.Empty, item.Size); if (item.BackgroundImage != null) { Rectangle clipRect = item.Selected ? item.ContentRectangle : bounds; ControlPaintEx.DrawBackgroundImage(graphics, item.BackgroundImage, this.ColorTable.Back, item.BackgroundImageLayout, bounds, clipRect); } if (item.CheckState == CheckState.Unchecked) { if (item.Selected) { Bitmap img = item.Pressed ? ((Bitmap)this.ColorTable.BaseItemDown) : ((Bitmap)this.ColorTable.BaseItemMouse); if (img != null) { ImageDrawRect.DrawRect(graphics, img, bounds, Rectangle.FromLTRB(this.ColorTable.BackRectangle.X, this.ColorTable.BackRectangle.Y, this.ColorTable.BackRectangle.Width, this.ColorTable.BackRectangle.Height), 1, 1); } else { Color baseItemHover = this.ColorTable.BaseItemHover; if (item.Pressed) { baseItemHover = this.ColorTable.BaseItemPressed; } RenderHelperStrip.RenderBackgroundInternal(graphics, bounds, baseItemHover, this.ColorTable.BaseItemBorder, this.ColorTable.Back, this.ColorTable.BaseItemRadiusStyle, this.ColorTable.BaseItemRadius, this.ColorTable.BaseItemBorderShow, this.ColorTable.BaseItemAnamorphosis, mode); } goto Label_0302; } if (!(toolStrip is ToolStripOverflow)) { goto Label_0302; } using (Brush brush = new SolidBrush(this.ColorTable.ItemHover)) { graphics.FillRectangle(brush, bounds); goto Label_0302; } } Bitmap baseItemMouse = (Bitmap)this.ColorTable.BaseItemMouse; Color baseColor = ControlPaint.Light(this.ColorTable.ItemHover); if (item.Selected) { baseColor = this.ColorTable.ItemHover; baseItemMouse = (Bitmap)this.ColorTable.BaseItemMouse; } if (item.Pressed) { baseColor = this.ColorTable.ItemPressed; baseItemMouse = (Bitmap)this.ColorTable.BaseItemDown; } if (baseItemMouse == null) { RenderHelperStrip.RenderBackgroundInternal(graphics, bounds, baseColor, this.ColorTable.BaseItemBorder, this.ColorTable.Back, this.ColorTable.BaseItemRadiusStyle, this.ColorTable.BaseItemRadius, this.ColorTable.BaseItemBorderShow, this.ColorTable.BaseItemAnamorphosis, mode); } else { ImageDrawRect.DrawRect(graphics, baseItemMouse, bounds, Rectangle.FromLTRB(this.ColorTable.BackRectangle.X, this.ColorTable.BackRectangle.Y, this.ColorTable.BackRectangle.Width, this.ColorTable.BackRectangle.Height), 1, 1); } Label_0302: graphics2.Dispose(); }
protected virtual void WmNcPaint(ref Message m) { IntPtr hDC = Win32.NativeMethods.GetWindowDC(m.HWnd); if (hDC == IntPtr.Zero) { return; } try { Rectangle bounds = new Rectangle(Point.Empty, base.Size); Rectangle client = base.ClientRectangle; client.X = _borderWidth; client.Y = _borderWidth; using (ImageDc bufferedDC = new ImageDc(base.Width, base.Height)) { Win32.NativeMethods.ExcludeClipRect( bufferedDC.Hdc, client.Left, client.Top, client.Right, client.Bottom); DrawTransparentBackground( bufferedDC.Hdc, bounds, base.Location); using (Graphics g = Graphics.FromHdc(bufferedDC.Hdc)) { using (GraphicsPath path = GraphicsPathHelper.CreatePath( bounds, _radius, _roundStyle, true)) { g.SetClip(path); } g.ExcludeClip(client); if (base.BackgroundImage != null) { ControlPaintEx.DrawBackgroundImage( g, base.BackgroundImage, base.BackColor, base.BackgroundImageLayout, bounds, bounds); } else if (base.BackColor != Color.Transparent) { using (Brush brush = new SolidBrush(base.BackColor)) { g.FillRectangle(brush, bounds); } } g.ResetClip(); using (GraphicsPath path = GraphicsPathHelper.CreatePath( bounds, _radius, _roundStyle, true)) { using (SmoothingModeGraphics antiGraphics = new SmoothingModeGraphics(g)) { g.DrawPath(Pens.Black, path); } } } Win32.NativeMethods.ExcludeClipRect( hDC, client.Left, client.Top, client.Right, client.Bottom); Win32.NativeMethods.BitBlt( hDC, bounds.X, bounds.Y, bounds.Width, bounds.Height, bufferedDC.Hdc, 0, 0, TernaryRasterOperations.SRCCOPY); } } catch { } finally { Win32.NativeMethods.ReleaseDC(m.HWnd, hDC); } }
protected override void OnRenderButtonBackground( ToolStripItemRenderEventArgs e) { ToolStripButton item = e.Item as ToolStripButton; if (item != null) { LinearGradientMode mode = e.ToolStrip.Orientation == Orientation.Horizontal ? LinearGradientMode.Vertical : LinearGradientMode.Horizontal; Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle bounds = new Rectangle(Point.Empty, item.Size); if (item.BackgroundImage != null) { Rectangle clipRect = item.Selected ? item.ContentRectangle : bounds; ControlPaintEx.DrawBackgroundImage( g, item.BackgroundImage, ColorTable.BackColorNormal, item.BackgroundImageLayout, bounds, clipRect); } if (item.CheckState == CheckState.Unchecked) { if (item.Selected) { Color color = ColorTable.BackColorHover; if (item.Pressed) { color = ColorTable.BackColorPressed; } RenderBackgroundInternal( g, bounds, color, ColorTable.BorderColor, ColorTable.BackColorNormal, RoundStyle.All, true, true, mode); return; } else { if (e.ToolStrip is ToolStripOverflow) { using (Brush brush = new SolidBrush(ColorTable.BackColorNormal)) { g.FillRectangle(brush, bounds); } return; } } } else { Color color = ControlPaint.Light(ColorTable.BackColorHover); if (item.Selected) { color = ColorTable.BackColorHover; } if (item.Pressed) { color = ColorTable.BackColorPressed; } RenderBackgroundInternal( e.Graphics, bounds, color, ColorTable.BorderColor, ColorTable.BackColorNormal, RoundStyle.All, true, true, mode); return; } } base.OnRenderButtonBackground(e); }
protected override void OnPaintBackground(PaintEventArgs e) { if (base.BackgroundImage != null) { Graphics g = e.Graphics; Rectangle bounds = new Rectangle(Point.Empty, base.Size); Rectangle clientRect = base.ClientRectangle; WINDOWINFO info = GetWindowInfo(); Point offset = new Point( info.rcClient.Left - info.rcWindow.Left, info.rcClient.Top - info.rcWindow.Top); IntPtr hDC = g.GetHdc(); try { using (ImageDc imageDc = new ImageDc(bounds.Width, bounds.Height)) { using (Graphics gDc = Graphics.FromHdc(imageDc.Hdc)) { ControlPaintEx.DrawBackgroundImage( gDc, base.BackgroundImage, base.BackColor, base.BackgroundImageLayout, bounds, bounds); } Win32.NativeMethods.BitBlt( hDC, clientRect.X, clientRect.Y, clientRect.Width, clientRect.Height, imageDc.Hdc, offset.X, offset.Y, TernaryRasterOperations.SRCCOPY); } } catch { } finally { g.ReleaseHdc(hDC); } return; } if (base.BackColor == Color.Transparent) { Graphics g = e.Graphics; IntPtr hDC = g.GetHdc(); try { WINDOWINFO info = GetWindowInfo(); Point offset = new Point( info.rcClient.Left - info.rcWindow.Left, info.rcClient.Top - info.rcWindow.Top); offset += (Size)base.Location; DrawTransparentBackground( hDC, base.ClientRectangle, offset); } catch { } finally { g.ReleaseHdc(hDC); } return; } base.OnPaintBackground(e); }