[聚合问答] How to change menu hover color

c#,winforms,winapi 2017-11-30 11 阅读

How to change the Hover (mouse over) color of a Windows application menu?

Any method in C# ?

OR

Any way by using Windows API (DllImport) ?

See image :

enter image description here

2个回答

44

You are using the MenuStrip class. You can override its renderer. Here's an example, pick your own colors please.

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        menuStrip1.Renderer = new MyRenderer();
    }

    private class MyRenderer : ToolStripProfessionalRenderer {
        public MyRenderer() : base(new MyColors()) {}
    }

    private class MyColors : ProfessionalColorTable {
        public override Color MenuItemSelected {
            get { return Color.Yellow; }
        }
        public override Color MenuItemSelectedGradientBegin {
            get { return Color.Orange; }
        }
        public override Color MenuItemSelectedGradientEnd {
            get { return Color.Yellow; }
        }
    }
}

Other properties of ProfessionalColorTable control other color elements.

2017-11-30
4

For changing the mouse-over border color (on items) use this:

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

2017-11-30

注:本文内容来自互联网,旨在为开发者提供分享、交流的平台。如有涉及文章版本等事宜,请你联系站长进行处理。