Change Menu Strip Highlight Color

lxXTaCoXxl

I know there are others out there who haven't figured it out yet I figure I'll help out. The code snippet included will over-ride the pre-designed menu highlight. :D

Just change the color of the pen or brush to whatever you want the highlight to be. :)


All of the references should already be included in your source at project creation.

1,891 Views
About the Author

I'm a very difficult person to describe because I'm all over the place. If I could sum me up into one word it would be insane. I'm an incredibly vibrant person. I love surfing, playing guitar, programming, photography, video games, skating, snowboarding, running parkour, hanging out with friends, spending time with my girlfriend, and much more. I'm currently enrolled in college courses and pursuing jobs in my area. Ask if you want to know more.

public Main()
        {
            InitializeComponent();

            // menuStrip1 is your menu strip's name, so change it accordingly.
            menuStrip1.Renderer = new myRenderer(); // Just add this line to public
        }

        // Put this in just below the main.
        private class myRenderer : ToolStripProfessionalRenderer
        {
            protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs myMenu)
            {
                if (!myMenu.Item.Selected)
                base.OnRenderMenuItemBackground(myMenu);

                else
                {
                    Rectangle menuRectangle = new Rectangle(Point.Empty, myMenu.Item.Size);

                    //Fill Color
                    myMenu.Graphics.FillRectangle(Brushes.DarkGreen, menuRectangle);

                    // Border Color
                    myMenu.Graphics.DrawRectangle(Pens.Lime, 1, 0, menuRectangle.Width - 2, menuRectangle.Height - 1);
                }
            }
        }