Custom Colours for .net Winforms Menus and Toolbars

Winforms doesn’t make customising standard controls very easy! This article shows you how to customise menus and toolbars with a fine level of granularity.

For controls such as ContextMenuStrip, MenuStrip and ToolbarStrip you are normally highly limited to the basics when it comes to changing their appearance and normally there’s a lot lacking. For example, with the context menu, you can change the background colour, but not the foreground! I stumbled across this task when trying to implement a “Dark Mode” for an application. Eventually the approach detailed below turned this:

into this:

In this example, I am applying these changes to a ContextMenuStrip. However, I think it should work with other types of toolbars and menus too. It was a bit of a faff, but I finally figured it. You have to use two particular class types to customise the rendering of these controls. A ToolStripProfessionalRenderer and a ProfessionalColorTable Class. You need to insert the two classes below into your code:

And..

Finally, you need to change a couple of properties on the relevant control. E.g.:

You can change the colours to match your requirements. There are other properties and methods that you can override in these rendering classes if needed. Links to a list of these below:

ToolStripProfessionalRenderer Microsoft Link
ProfessionalColorTable Microsoft Link

Enjoy!

About stigzler 48 Articles
Chief crook and wattle bosher.

Be the first to comment

Leave a Reply

Your email address will not be published.


*