protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
{
if ((e.ToolStrip is ContextMenuStrip) ||
(e.ToolStrip is ToolStripDropDownMenu))
{
// Make sure the font is current
if (e.ToolStrip.Font != KCT.MenuStripFont)
e.ToolStrip.Font = KCT.MenuStripFont;
// Create border and clipping paths
using (GraphicsPath borderPath = CreateBorderPath(e.AffectedBounds, _cutContextMenu),
clipPath = CreateClipBorderPath(e.AffectedBounds, _cutContextMenu))
{
// Clip all drawing to within the border path
using (Clipping clipping = new Clipping(e.Graphics, clipPath))
{
// Create the background brush
using (SolidBrush backBrush = new SolidBrush(KCT.ToolStripDropDownBackground))
e.Graphics.FillPath(backBrush, borderPath);
}
}
}
else if (e.ToolStrip is StatusStrip)
{
// Make sure the font is current
if (e.ToolStrip.Font != KCT.StatusStripFont)
e.ToolStrip.Font = KCT.StatusStripFont;
// We do not paint the top two pixel lines, as they are drawn by the status strip border render method
RectangleF backRect = new RectangleF(0, 1.5f, e.ToolStrip.Width, e.ToolStrip.Height - 2);
// Cannot paint a zero sized area
if ((backRect.Width > 0) && (backRect.Height > 0))
{
using (LinearGradientBrush backBrush = new LinearGradientBrush(backRect,
KCT.StatusStripGradientBegin,
KCT.StatusStripGradientEnd,
90f))
{
backBrush.Blend = _stripBlend;
e.Graphics.FillRectangle(backBrush, backRect);
}
}
}
else
{
// Make sure the font is current
if (e.ToolStrip is MenuStrip)
{
if (e.ToolStrip.Font != KCT.MenuStripFont)
e.ToolStrip.Font = KCT.MenuStripFont;
base.OnRenderToolStripBackground(e);
}
else
{
if (e.ToolStrip.Font != KCT.ToolStripFont)
e.ToolStrip.Font = KCT.ToolStripFont;
// Cannot paint a zero sized area
RectangleF backRect = new RectangleF(0, 0, e.ToolStrip.Width, e.ToolStrip.Height);
if ((backRect.Width > 0) && (backRect.Height > 0))
{
if (e.ToolStrip.Orientation == Orientation.Horizontal)
{
using (LinearGradientBrush backBrush = new LinearGradientBrush(backRect,
KCT.ToolStripGradientBegin,
KCT.ToolStripGradientEnd,
90f))
{
backBrush.Blend = _stripBlend;
e.Graphics.FillRectangle(backBrush, backRect);
}
using (Pen darkBorder = new Pen(KCT.ToolStripBorder),
lightBorder = new Pen(KCT.ToolStripGradientBegin))
{
e.Graphics.DrawLine(lightBorder, 0, 2, 0, e.ToolStrip.Height - 2);
e.Graphics.DrawLine(lightBorder, e.ToolStrip.Width - 2, 0, e.ToolStrip.Width - 2, e.ToolStrip.Height - 2);
e.Graphics.DrawLine(darkBorder, e.ToolStrip.Width - 1, 0, e.ToolStrip.Width - 1, e.ToolStrip.Height - 1);
}
}
else
{
using (LinearGradientBrush backBrush = new LinearGradientBrush(backRect,
KCT.ToolStripGradientBegin,
KCT.ToolStripGradientEnd,
0f))
{
backBrush.Blend = _stripBlend;
e.Graphics.FillRectangle(backBrush, backRect);
}
using (Pen darkBorder = new Pen(KCT.ToolStripBorder),
lightBorder = new Pen(KCT.ToolStripGradientBegin))
{
e.Graphics.DrawLine(lightBorder, 1, 0, e.ToolStrip.Width - 2, 0);
e.Graphics.DrawLine(lightBorder, 1, e.ToolStrip.Height - 2, e.ToolStrip.Width - 2, e.ToolStrip.Height - 2);
e.Graphics.DrawLine(darkBorder, e.ToolStrip.Width - 1, 0, e.ToolStrip.Width - 1, e.ToolStrip.Height - 1);
}
}
}
}
}
}