How to customize toolstrip button highlight color on mouse over

Ahmad picture Ahmad · Mar 20, 2015 · Viewed 8.8k times · Source

I use a ToolStrip in a C# winform application.
As I move the mouse over a button it gets highlighted (transparent blue color), I would like to change this color

I tried to use a custom renderer class

 toolStrip1.Renderer = new MyRenderer();
 ....
 class MyRenderer : ToolStripProfessionalRenderer
 {
 }

However, I don't know which method I should override to change that color.

Answer

Ivan Jovović picture Ivan Jovović · Mar 20, 2015

Actually, there is no built-in way (or at least I am not aware of it).

class MyRenderer : ToolStripProfessionalRenderer
{
    protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
    {
        if (!e.Item.Selected)
        {
            base.OnRenderButtonBackground(e);
        }
        else
        {
            Rectangle rectangle = new Rectangle(0, 0, e.Item.Size.Width - 1, e.Item.Size.Height - 1);
            e.Graphics.FillRectangle(Brushes.Green, rectangle);
            e.Graphics.DrawRectangle(Pens.Olive, rectangle);
        }
    }
}