简体   繁体   中英

How do I change the default back colors of a ToolStripMenuItem when hovered and clicked?

Just attempting to make my UI less Windows-looking. I was testing a few of the item's events and tried controlling the background using the BackColor property, but to no avail. Is there any convenient way to alter the default colors?

Thanks in advance.

The menu item's back color turns light-blue when hovered by the cursor.

When an item is clicked, its back color turns light-gray, making the item's text hardly visible.

Simply create your ow color table from the ProfessionalColorTable.

private class MyColours : ProfessionalColorTable
{
    public override Color MenuItemSelected
    {
        get { return Color.Blue; }
    }
    public override Color MenuItemSelectedGradientBegin
    {
        get { return Color.DarkCyan; }
    }
    public override Color MenuItemSelectedGradientEnd
    {
        get { return Color.Cyan; }
    }

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

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

Add another class to render these colors as follows.

private class NewColourRenderer : ToolStripProfessionalRenderer
{
    public NewColourRenderer(): base(new MyColours()){}            
}

Then use your new renderer in the form load event:

menuStrip1.Renderer = new NewColourRenderer();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM