Reputation: 2735
I have a WinForms program which has a MenuStrip
control at the top of the form. Each ToolStripMenuItem
in the MenuStrip
has a drop-down with a bunch of selections (New, Open, Save,... the usual fare).
I would like to change the color of the menu, and doing so on each of the individual parts works well enough. Unfortunately there seems to be a ToolStripDropDown
control which is implicitly added to each of the menu items to hold their children, and it shows up in the native system colors and gives everything an ugly border:
Since the drop-down seems to be created implicitly by the menu items, I can't find any way to access it. Is it possible to change the background and foreground colors of the drop-down control, or will I have create it by hand outside of the designer?
Upvotes: 1
Views: 3886
Reputation: 2735
I've opted for a more complete option inspired by the answers at How to change Menu hover color - WINFORMS. By creating a subclass of ProfessionalColorTable
with all the potentially useful colors overriden (abridged code):
public class CustomColorTable : ProfessionalColorTable
{
//a bunch of other overrides...
public override Color ToolStripBorder
{
get { return Color.FromArgb(0, 0, 0); }
}
public override Color ToolStripDropDownBackground
{
get { return Color.FromArgb(64, 64, 64); }
}
public override Color ToolStripGradientBegin
{
get { return Color.FromArgb(64, 64, 64); }
}
public override Color ToolStripGradientEnd
{
get { return Color.FromArgb(64, 64, 64); }
}
public override Color ToolStripGradientMiddle
{
get { return Color.FromArgb(64, 64, 64); }
}
}
and then adding the following to the constructor to my form:
this.menuStrip_Main.RenderMode = ToolStripRenderMode.Professional;
this.menuStrip_Main.Renderer = new ToolStripProfessionalRenderer(new CustomColorTable());
The renderer takes care of all the heavy lifting, and everything looks great. Best of all the designer can still be used to work with the MenuStrip
and its children, though the appearance no longer matches.
Upvotes: 2