How do you change the default background color for

2020-07-22 16:04发布

问题:

These days with Visual C# (Visual C# 2008 specifically) it seems that the default color for menustrips and menus is blue, which to me looks really strange and is something that I'd really like to override. I'm guessing that Visual Studio is picking up this blue color from my selected system theme or something, however no other Windows app running on my system has this blue color so I don't know why my .NET apps would have to have it. ;)

Anyway, I noticed that if I create an application using an older version of Visual Studio (Visual Studio.NET), the default background color for menustrips and menus is the standard gray that you'd expect to see. This is one solution to the problem I suppose, but it seems like kind of a stupid one and I'd really like to find a way to override it in the current version of Visual C#.

回答1:

DotNet 1.x didn't have a MenuStrip, and used a standard Windows menu.

DotNet versions 2.0 and up have the MenuStrip, and VS 7 and up removes the MainMenu from the toolbox and replaces it with a MenuStrip, which uses the Office Xp 2003 theme, hence the blue color scheme for the MenuStrip and ToolStrip.

The MainMenu can still be added to the toolbox for a standard Windows menu.



回答2:

Set the "RenderMode" option of the MenuStrip to "System" instead of "managerRenderMode"

:)



回答3:

Have you tried setting the back color of your menuStrip? You should be able to do something like:

this.menuStrip1.BackColor = Color.FromKnownColor(KnownColor.Control);


回答4:

You can make own Renderer

    public class BrowserMenuRenderer : ToolStripProfessionalRenderer
{
    public BrowserMenuRenderer() : base(new BrowserColors()) {}
}
public class BrowserColors : ProfessionalColorTable
{
    public override Color MenuItemSelected
    {
        get { return Color.FromArgb(30, 30, 30); }
    }
    public override Color MenuItemBorder
    {
        get { return Color.FromArgb(30, 30, 30); }
    }
    public override Color MenuItemSelectedGradientBegin
    {
        get { return Color.FromArgb(30, 30, 30); }
    }
    public override Color MenuItemSelectedGradientEnd
    {
        get { return Color.FromArgb(30, 30, 30); }
    }
}

Then you just set your menustrip's renderer as YourRenderer



回答5:

You can use the render mode but that only sets the system theme to default. .net allows you to change the backcolor and the for color but when you hover over it It still shows the default colors. Heres a way around that...

his is very simple to accomplish by using the "DropDownOpening" , "DropDownClosed", and "MouseEnter" events.

private void fileToolStripMenuItem_DropDownOpening(object sender, EventArgs e){

    // When the user clicks on "File" it will change to red.
    fileToolStripMenuItem.ForeColor = Color.Red;
}


private void testToolStripMenuItem_MouseEnter(object sender, EventArgs e){

    // When the user hovers over a child of "file" called "test", "file" turns orange.
    fileToolStripMenuItem.ForeColor = Color.Orange;
}


private void test2ToolStripMenuItem_MouseEnter(object sender, EventArgs e){

    // When the user hovers on a child of "file" called "test2", "file" turns blue.
    fileToolStripMenuItem.ForeColor = Color.Blue;
}


private void fileToolStripMenuItem_DropDownClosed(object sender, EventArgs e){

    // When the user leaves the "file" menu, it gets restored back to black.
    fileToolStripMenuItem.ForeColor = Color.Black;
}