Change highlight color in MenuStrip items

0

I am working with C # in which I will develop an application that contains a menu which can be dynamic. I chose to work with MenuStrip, it's the first time I've done it.

I want to make my menu bar black with the blank font. I doubt it is how I can change the background color and the letters when I mouse over.

In the following photo you can see that when passing over it has a blue color which does not highlight and does not allow to see the text in a comfortable way. Likewise when pressed it is seen in a white tone that completely loses sight of the text.

How could I adjust these color values of both the background and the letter by passing it over with the mouse and when clicking on this MenuTrip.

Or if someone could give me another option to create a menu within C # I would appreciate it a lot.

Thanks in advance, greetings, good afternoon.

    
asked by Ezequie Lopez 15.08.2018 в 23:57
source

1 answer

1

What you need to do is change the renderer from your menu.

First, the namespace Drawing imports.

using System.Drawing;

Add this code in the constructor of your form. Substitute NombreMenu for the name of your menu, most of the time it's menuStrip1 .

    public RelojKarosso()
    {
        InitializeComponent();
        NombreMenu.Renderer = new MiRenderizador();
    }

And add this private class.

    private class MiRenderizador: ToolStripProfessionalRenderer
    {
        protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
        {
            if (!e.Item.Selected) base.OnRenderMenuItemBackground(e);
            else
            {
                Rectangle rc = new Rectangle(Point.Empty, e.Item.Size);
                e.Graphics.FillRectangle(Brushes.Yellow, rc); //Elige el color que desees
                e.Graphics.DrawRectangle(Pens.Black, 1, 0, rc.Width - 2, rc.Height - 1);
            }
        }
    }
    
answered by 17.08.2018 / 01:26
source