How to change the appearance of a MenuStrip [duplicate]
Asked Answered
S

2

5

I add a MenuStrip in my app and is add on ManagerRenderMode at Render Mode. The problem is with the appearance, look offal. Look at those two photos, I want to change that white border of submenus in transparent, that blue rectangule that look offal on gray for the menu and for the submenu in dark gray (and his border that is a dark blue) and the border white of menu when is selected. How I can do this ?

BackColor is: 36; 36; 36 and ForeColor is LightGray.

enter image description here

enter image description here

I managed to change the blue rectangle, the white rectangle when the option is selected, the blue rectangle when I select an option of submenus, but I don't know how to change the white border, please help..

Here is the code so far...

        Color culoare = Color.FromArgb(20, 20, 20);
        Color culoare1 = Color.FromArgb(36, 36, 36);

        public override Color MenuItemSelected
        {
            get { return culoare; }
        }

        public override Color MenuItemBorder
        {
            get { return culoare; }
        }

        public override Color MenuItemSelectedGradientBegin
        { 
            get { return culoare; } 
        }

        public override Color MenuItemSelectedGradientEnd
        { 
            get { return culoare; } 
        }

        public override Color MenuItemPressedGradientBegin
        { 
            get { return culoare; }
        }

        public override Color MenuItemPressedGradientEnd
        {
            get { return culoare; }
        }

        public override Color MenuBorder
        {
            get { return culoare; }
        }
Spitz answered 5/11, 2012 at 15:52 Comment(0)
M
19

You can do this by creating your own ColorTable, and overriding the properties you wish to change the colour of:

public  class TestColorTable : ProfessionalColorTable
{
    public override Color MenuItemSelected
    {
        get { return Color.Red; }
    }

    public override Color MenuBorder  //added for changing the menu border
    {
        get { return Color.Green; }
    }

}

You would use it like this:

private void Form1_Load(object sender, EventArgs e)
{
    menuStrip1.Renderer = new ToolStripProfessionalRenderer(new TestColorTable());
}
Mook answered 5/11, 2012 at 16:17 Comment(5)
Kinda what I was getting at, except I took the drawing approach. This is probably simpler for the OP's needs. vote++;Farmyard
Your method help me, but I don't know how to change to the border of submenus (secound picture, the white border). Help..Spitz
@AnDr3yy: See my edit - It appears to be the MenuBorder property you need to override for that.Mook
woah, thanks! I didn't even knew this was possible, a whole new world opens for me :DWhitehurst
Even nicer VisualStudio is giving suggestions for the other possibilities in overriding. Thanks very much for this!!! Upped.Etherege
F
4

Your approach is incorrect. You do not style menus and toolstrips using forecolor/backcolor.

Take a look at ToolStripProfessionalRenderer

Example on how to use this

public class MyToolStripRenderer : ToolStripProfessionalRenderer
{
    /* override styling/drawing here */
}

MenuStrip strip = new MenuStrip();

strip.Renderer = new MyToolStripRenderer();

//this will set RenderMode to "Custom"

consider using this example on CodeProject as some research.

Better still, VBForums have loads of them, already implemented (in the usual Luna, Office, Windows, Visual Studio styles!)

http://www.vbforums.com/showthread.php?596563-100-Customizable-MenuStrip-ToolStrip-StatusStrip-including-common-presets

If you simply want to chaneg the colors...use Pondidum's answer! It involves less work!

Farmyard answered 5/11, 2012 at 16:16 Comment(2)
The vbforums link is very interesting, and your method certainly provides more control (overriding appearance, rather than just colours).Mook
How can i can i change the location of the elementToolStripMenuItem.Is there any way to set the location for the elementToolstripMenuItemDome

© 2022 - 2024 — McMap. All rights reserved.