protected override void OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs e) { ToolStrip toolStrip = e.ToolStrip; ToolStripDropDownItem item = e.Item as ToolStripDropDownItem; if (item != null) { LinearGradientMode mode = toolStrip.Orientation == Orientation.Horizontal ? LinearGradientMode.Vertical : LinearGradientMode.Horizontal; Graphics graphics = e.Graphics; SmoothingModeGraphics sg = new SmoothingModeGraphics(graphics); Rectangle bounds = new Rectangle(Point.Empty, item.Size); if (item.Pressed && item.HasDropDownItems) { GraphicsHelper.DrawBackground( graphics, bounds, StyleSheet.HeadToolStripItemPressedBackColor, StyleSheet.HeadToolStripItemBorderColor, StyleSheet.HeadToolStripItemInnerBorderColor, RoundStyle.All, 8, 0.45f, true, true, mode); } else if (item.Selected) { GraphicsHelper.DrawBackground( graphics, bounds, StyleSheet.HeadToolStripItemHoveringBackColor, StyleSheet.HeadToolStripItemBorderColor, StyleSheet.HeadToolStripItemInnerBorderColor, RoundStyle.All, 8, 0.45f, true, true, mode); } else if (toolStrip is ToolStripOverflow) { using (Brush brush = new SolidBrush(StyleSheet.HeadToolStripItemInnerBorderColor)) { graphics.FillRectangle(brush, bounds); } } else { base.OnRenderDropDownButtonBackground(e); } sg.Dispose(); } }
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { ToolStrip toolStrip = e.ToolStrip; var isHeadControl = false; if (toolStrip.Tag != null && toolStrip.Tag.ToString().Contains("$")) { isHeadControl = true; } var item = e.Item as ToolStripButton; Graphics graphcs = e.Graphics; if (item != null) { LinearGradientMode mode = toolStrip.Orientation == Orientation.Horizontal ? LinearGradientMode.Vertical : LinearGradientMode.Horizontal; var smoothGraphics = new SmoothingModeGraphics(graphcs); var bounds = new Rectangle(Point.Empty, item.Size); if (item.BackgroundImage != null) { Rectangle clipRect = item.Selected ? item.ContentRectangle : bounds; GraphicsHelper.DrawBackgroundImage( graphcs, item.BackgroundImage, isHeadControl ? StyleSheet.HeadToolStripItemInnerBorderColor : StyleSheet.ControlInnerBorderColor, item.BackgroundImageLayout, bounds, clipRect); } if (item.CheckState == CheckState.Unchecked) { if (item.Selected) { Color color = isHeadControl ? StyleSheet.HeadToolStripItemHoveringBackColor : StyleSheet.ControlHoveringBackColor; if (item.Pressed) { color = isHeadControl ? StyleSheet.HeadToolStripItemPressedBackColor : StyleSheet.ControlPressedBackColor; } GraphicsHelper.DrawBackground( graphcs, bounds, color, isHeadControl ? StyleSheet.HeadToolStripItemBorderColor : StyleSheet.ControlBorderColor, isHeadControl ? StyleSheet.HeadToolStripItemInnerBorderColor : StyleSheet.ControlInnerBorderColor, isHeadControl ? RoundStyle.All : RoundStyle.None, isHeadControl ?8:0, isHeadControl ?0.45f:0f, true, true, mode); } else { if (toolStrip is ToolStripOverflow) { using (Brush brush = new SolidBrush(isHeadControl ? StyleSheet.HeadToolStripItemHoveringBackColor : StyleSheet.ControlHoveringBackColor)) { graphcs.FillRectangle(brush, bounds); } } } } else { Color color = ControlPaint.Light(isHeadControl ? StyleSheet.HeadToolStripItemHoveringBackColor : StyleSheet.ControlHoveringBackColor); if (item.Selected) { color = isHeadControl ? StyleSheet.HeadToolStripItemHoveringBackColor : StyleSheet.ControlHoveringBackColor; } if (item.Pressed) { color = isHeadControl ? StyleSheet.HeadToolStripItemPressedBackColor : StyleSheet.ControlPressedBackColor; } GraphicsHelper.DrawBackground( graphcs, bounds, color, isHeadControl ? StyleSheet.HeadToolStripItemBorderColor : StyleSheet.ControlBorderColor, isHeadControl ? StyleSheet.HeadToolStripItemInnerBorderColor : StyleSheet.ControlInnerBorderColor, isHeadControl ? RoundStyle.All : RoundStyle.None, isHeadControl ? 8 : 0, isHeadControl ? 0.45f : 0f, true, true, mode); } smoothGraphics.Dispose(); } }