7
votes

I found this page, which outlines how to change the rendering for a MenuStrip and its items.

I want to use this, but the problem is that the highlight color when you hover over a button doesn't match it.

Is there any way to change the highlight color from blue to yellow? I've tried using the MouseHover and MouseLeave events, but for some reason they're really slow, and they change the button to a solid color, which looks bad, but leaves a border on the edge of the button that doesn't change.

In the designer:

this.ButtonName.MouseHover += new System.EventHandler(button_mousehover);

And then in the Code:

private void button_mousehover(object sender, EventArgs e)
{
    Button btn = sender as Button;
    btn.BackColor = Color.Yellow;
}

Is there anything as easy as in the link I posted above to change the highlight color from blue to something else?

Here's the code for changing the rendering of the menu strip:

private void myForm Load(object sender, EventArgs e)
{
    myMenuStrip.Renderer = new MenuRenderer();
{

private class MenuRenderer : ToolStripProfessionalRenderer
{
    public MenuRenderer() : base(new MyColors()) { }
}

private class MyColors : ProfessionalColorTable
{
    public override Color MenuItemSelectedGradientBegin
    {
        get { return Color.Orange; }
    }
    public override Color MenuItemSelectedGradientEnd
    {
        get { return Color.Yellow; }
    }
    public override Color MenuItemPressedGradientBegin
    {
        get{ return Color.Yellow; }
    }
    public override Color MenuItemPressedGradientEnd
    {
        get { return Color.Orange; }
    }
    public override Color MenuItemSelected
    {
        get { return Color.Gold; }
    }
}

So it'll change the background of a hovered-over menu item to an orange-yellow gradient, change it to a yellow-orange gradient on click, and any item in the menu will have a gold highlight on hovering.

What I'm trying to do is do that last part (change the highlight to gold/yellow) for the buttons in my form.

2
Can you post your code for changing the rendering of a MenuStrip item?Tomer
Sure, just one moment, I'll edit it into the comment.electroball09
wait, what colors you don't see that you expect to see?Tomer
I can see the highlight color as you described. When I hover over the MenuItems I can see them gold.Tomer
Have you tried FlatAppearance property?Baz Guvenkaya

2 Answers

14
votes

In the properties of the button:

under FlatStyle, select Flat.

Then, expand FlatAppearance and under MouseOverBackColor, select the highlight color you want. Alternatively, you can also enter the RGB color you want, under the MouseOverBackColor.

1
votes

You can take a look at the Button Renderer.

Why do you want to override the renderer when you can simply subscribe to the MouseHover event like so:

this.someButtonName.MouseHover += (s,e) => 
{
   this.someButtonName.BackColor = Color.Yellow;
};

I recommend you use a mouse leave too in order to reset the button to it's initial color when your mouse isn't on it anymore.