Change Menu Strip Highlight Color

lxXTaCoXxl 0 Tallied Votes 3K Views Share

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.

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);
                }
            }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.