0

So I have a MenuStrip with a couple of ToolStripMenuItems. Two of my ToolStripMenuItem components are having a background image (battery icon and shutdown icon).

Now I want to disable the default MenuStrip mouse hover effect (that blueish background) for the ToolStripMenuItem elements which I have set a background. To achieve this I have override the OnRenderMenuItemBackground event implementation, like this:

internal class NoHighlightRenderer : ToolStripProfessionalRenderer
    {
        protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
        {
            if (e.Item.OwnerItem != null)
            {
                base.OnRenderMenuItemBackground(e);
            }
        }
    }

And use this custom renderer for my MenuStrip like this:

myMenuStrip.Renderer = new NoHighlightRenderer();

This works fine for the elements that don't have a background image set. For the ones with the background set, the background image will not show.

I want the background image to be visible, how to do this?

mariusmmg2
  • 713
  • 18
  • 37
  • https://stackoverflow.com/questions/9260303/how-to-change-menu-hover-color – Hans Passant Apr 18 '19 at 21:33
  • @HansPassant Well I tried to override `MenuItemSelected`, `MenuItemSelectedGradientBegin`, and `MenuItemSelectedGradientEnd` to `Color.Transparent`, but that didn't what I need. Any other ideas? – mariusmmg2 Apr 19 '19 at 05:49

0 Answers0