Search code examples
c#colorsmenustrip

C# how to change menuStrip hover color?


Good day people, I want to change the color of a menu item on my menuStrip when I hover above it. Can anyone help me?

enter image description here


Solution

  • You can't do this using the normal MouseEnter and MouseLeave events. You need to directly override the menu rendering. You can do something like this, using the MenuStrip class:

    private class renderer : ToolStripProfessionalRenderer {
        public renderer() : base(new cols()) {}
    }
    
    private class cols : ProfessionalColorTable {
        public override Color MenuItemSelected {
            // when the menu is selected
            get { return Color.Blue; }
        }
        public override Color MenuItemSelectedGradientBegin {
            get { return Color.Black; }
        }
        public override Color MenuItemSelectedGradientEnd {
            get { return Color.White; }
        }
    }
    

    And just in case you're interested, this is what happens when you use the MouseEnter and MouseLeave events. (Inside the MouseEnter event, it was making the BackgroundColor green, however that was not been called):

    Only the leave event was been called.