Search code examples
c#winformsrenderermenustrip

'White bar' on MenuStripDropDown


I currently have a custom Render set up for a MenuStrip on a C# windows forms application:

        private class HeaderMenuRender : ProfessionalColorTable
    {
        public override Color MenuItemSelectedGradientBegin
        {
            get
            {
                return Color.Gray;
            }
        }

        public override Color MenuItemSelectedGradientEnd
        {
            get
            {
                return Color.Gray;
            }
        }

        public override Color MenuItemPressedGradientBegin
        {
            get
            {
                return Color.Gray;
            }
        }

        public override Color MenuItemPressedGradientEnd
        {
            get
            {
                return Color.Gray;
            }
        }

        public override Color MenuItemBorder
        {
            get
            {
                return Color.Gray;
            }
        }

        public override Color MenuBorder
        {
            get
            {
                return Color.Gray;
            }
        }
    }

This is then applied to an existing MenuStrip control on a form to create a Custom render.

However when running the application and making a selection from the menu which is displayed, despite the Menu options being the correct colour, there is a small 'White' (arguably could be 'Control' colour) bar which spans the length of the selected MenuStrip option (indicated in the blue box below):

MenuStrip 'White' Bar

Is there a particular property of the custom Renderer that I am not including or something I am missing which is setting this specific part of the MenuStrip selected item? The examples I have seen elsewhere do not seem to have this issue.


Solution

  • In the above code, it seems you made items Gray using BackColor property.

    You can use override ToolStripDropDownBackground to return Color.Gray, this removes that while line.

    Also you can overriding ImageMarginGradientBegin, ImageMarginGradientMiddle and ImageMarginGradientEnd to make also image/checkbox area Gray.

    Here is What I added to your codes to get the desired value:

    public override Color ImageMarginGradientBegin
    {
        get { return Color.Gray; }
    }
    
    public override Color ImageMarginGradientMiddle
    {
        get { return Color.Gray; }
    }
    
    public override Color ImageMarginGradientEnd
    {
        get { return Color.Gray; }
    }
    
    public override Color ToolStripDropDownBackground
    {
        get { return Color.Gray; }
    }