You can implement your custom Renderer
and override OnRenderArrow
and OnRenderItemCheck
and pass your custom ColorTable
to it. Then set it as Renderer
of your ContextMenu
.
Code for ColorTable:
public class MyColorTable : ProfessionalColorTable
{
public override Color MenuItemBorder
{
get { return Color.WhiteSmoke; }
}
public override Color MenuItemSelected
{
get { return Color.WhiteSmoke; }
}
public override Color ToolStripDropDownBackground
{
get { return Color.White; }
}
public override Color ImageMarginGradientBegin
{
get { return Color.White; }
}
public override Color ImageMarginGradientMiddle
{
get { return Color.White; }
}
public override Color ImageMarginGradientEnd
{
get { return Color.White; }
}
}
Code for Renderer:
public class MyRenderer : ToolStripProfessionalRenderer
{
public MyRenderer()
: base(new MyColorTable())
{
}
protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
var r = new Rectangle(e.ArrowRectangle.Location, e.ArrowRectangle.Size);
r.Inflate(-2, -6);
e.Graphics.DrawLines(Pens.Black, new Point[]{
new Point(r.Left, r.Top),
new Point(r.Right, r.Top + r.Height /2),
new Point(r.Left, r.Top+ r.Height)});
}
protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
var r = new Rectangle(e.ImageRectangle.Location, e.ImageRectangle.Size);
r.Inflate(-4, -6);
e.Graphics.DrawLines(Pens.Black, new Point[]{
new Point(r.Left, r.Bottom - r.Height /2),
new Point(r.Left + r.Width /3, r.Bottom),
new Point(r.Right, r.Top)});
}
}
Code for Form Load:
private void Form_Load(object sender, EventArgs e)
{
this.contextMenuStrip1.Renderer = new MyRenderer();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…