"Wyatt Says..." is a collection of articles by Wyatt O'Day talking about wyDay products and the things we've learned along the way.
A question I see raised often on forums is some variation on “how do I get menus that look like Vista’s menus: icons with the baby-blue selection highlight.” Or, how do I get my menus to look like Windows Explorer context menus:
The first thing you should notice is the light-blue gradient used for the selection highlight. The second thing is the alpha-blended icon (that is, the icon has partially transparent pixels that blend nicely with the light-blue gradient).
But how do you get that look without owner-drawing your menu items? There was a nice post over at Mircosoft’s Shell Blog describing how to do it in C++. I’ve taken the applicable parts of the C++ code and ported them to a nice little interface for .NET languages. That is, you’ll be able to use my code with C#, VB.NET, and any other .NET languages that exists.
Here’s a screenshot of the interface I created (called VistaMenu) running in Windows Vista, Windows XP, and Windows 98:
As you can see, I took the time to make sure the VistaMenu worked and looked good even in the older Windows systems.
How to use VistaMenu
You need to add ContextMenu, MainMenu, and VistaMenu controls to the Visual Studio toolbox:
This should add all the necessary controls to the Toolbox. Now just drag the VistaMenu control to your form (you only need one VistaMenu per Form), a MainMenu, and any number of ContextMenus.
All you have to do now is click a menu items, and in the the Properties window select an Image. No messy ImageList is necessary:
You should know…
As I mentioned parenthetically above, you only need one VistaMenu per form. This one VistaMenu component handles all the MenuItems for the MainMenu and all ContextMenus on your Form. If you add more than one ‘VistaMenu’ component you’ll waste resources and your program will likely crash.
Also, VistaMenu is for ContextMenus and MainMenus, NOT ContextMenuStrips and MenuStrips. They’re completely different controls.
Also out, SplitButton 2.0
Version 2.0 of the SplitButton adds support for ContextMenu in addition to ContextMenuStrip. Now you can use the shiny new VistaMenu with the SplitButton.
This is a breaking change, however. Previously you had to set the ‘SplitMenu’ property with a ContextMenuStrip, but in this version there are two properties: ‘SplitMenu’ and ‘SplitMenuStrip’. Where ‘SplitMenu’ takes a ContextMenu, while ‘SplitMenuStrip’ takes a ContextMenuStrip.
Questions, comments, complaints…
Take a trip over to the forum and let me have it. No registration is required, and all input is welcome.
Download VistaMenu: Includes the source code, a compiled binary, and demo projects for both C# and VB.NET.
Download SplitButton v2.0: Includes the source code and the compiled binary. It works with every .NET language.
Subscribe to the 'Wyatt Says...' RSS Feed and keep up to date on on my articles on updaters, usability, open source C# components, and software licensing.