4

I have an application that contains a lot of menuitems. I have changed the background of the menuitem into dark gray and the text into white but the arrow near the text is still black. I want to change the color of this arrow into white.

I've found the exlanation in this document:

MenuItem.OwnerDraw Property

and a similar question on stackoverflow:

Question on stackoverflow

It is possible to change the color of the arrow next to a menuitem in a easier way? (This is the arrow that allows you to display a submenu). I mean using something like ProfessionalColorTable.

Community
  • 1
  • 1
Martina
  • 791
  • 1
  • 14
  • 26

1 Answers1

6

Inspiration was this very good answer by @Hans Passant. enter image description here Provide a custom renderer for your menu strip on form load or constructor like:

this.menuStrip.Renderer = new WhiteArrowRenderer();

and override the arrow paint:

public class WhiteArrowRenderer : ToolStripProfessionalRenderer { 
    protected override void OnRenderArrow (ToolStripArrowRenderEventArgs e) { 
        var tsMenuItem = e.Item as ToolStripMenuItem;
        if (tsMenuItem != null)
            e.ArrowColor = Color.White;
        base.OnRenderArrow(e);
    }
}
Community
  • 1
  • 1
andrei.ciprian
  • 2,895
  • 1
  • 19
  • 29
  • This is really useful. I tried it and it works. Unfortunately, this solution remove another change that I made. I used this code to override some methods to change some colors: ToolStripProfessionalRenderer toolStripProfessionalRenderer = new ToolStripProfessionalRenderer(new MyColorTable()); ToolStripManager.Renderer = toolStripProfessionalRenderer; With the new code I lose the old changes. How can I solve this? Thank you very much – Martina Oct 28 '14 at 12:10
  • Merge the existing color table to the custom renderer that can handle arrows too. – andrei.ciprian Oct 28 '14 at 12:20
  • What do you mean? I've tryed to do this: CustomToolStripRenderer customRenderer = new ustomToolStripRenderer(new ToolStripProfessionalRenderer(new MyColorTable())); customRenderer.Render(); public void Render(){ ToolStripManager.Renderer = _toolStripRenderer; } protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e){var tsMenuItem = e.Item as ToolStripMenuItem; if (tsMenuItem != null) e.ArrowColor = Color.White; base.OnRenderArrow(e);} and in this way the arrows remains black because with ToolStripManager.Renderer = _toolStripRenderer I override the renderer. – Martina Oct 28 '14 at 15:44
  • Totally replace the existing `ToolStripProfessionalRenderer` with the custom `WhiteArrowRenderer`.Use the constructor that also customizes the color table. By merging I mean merging, 2 in 1. No offense, this is a totally different question. As far as I am concerned other conflicts in your app defeat the purpose of this question. – andrei.ciprian Oct 28 '14 at 16:06
  • Yes, you're right. The initial question was correct but I noticed another problem after solving the initial question. I should post a new question, since the problem is different from the original one. I do it now since the last change you suggested to me, unfortunately, does not work. Thank you – Martina Oct 28 '14 at 16:42
  • The follow-up question is [here](https://stackoverflow.com/q/26614398/6674014). You need both for this to work. – DCOPTimDowd Oct 04 '17 at 21:19