The wyDay blog is where you find all the latest news and tips about our existing products and new products to come.
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 our blog's RSS Feed or follow Wyatt (CEO of wyDay) on Mastodon (@email@example.com) to keep up-to-date with our latest posts.
This is fantastic. Thanks heaps for building this for us to use.
Thank you very much, I've been looking for something like this very long. Don't know why MenuStrips and the others are not using default system style :-S
I'm glad I could help. The reason the MenuStrip components don't use the system styling is that Vista was still in development when .NET 2.0 was released (end of 2004, beginning of 2005).
But the "problem" exists on .NET 3.5, using Visual C# 2008 Express.
Right, but .NET 3.0 (and 3.5) are just layers on top of 2.0 - they don't replace 2.0.
But I agree that Microsoft should have released a new collection of components to work with Vista & Windows 7, but I'm glad to fill in the gaps.
Thanks for the useful control, I will be using it in my most recent program. I will put a link to this site in the credits. Works great by the way.
- Daniel Sage
MIIM_BITMAP is supported since Windows 2000. Why you use ownerdraw for menu in OS early than vista? :confused: it (MIIM_BITMAP) might work in 2000 and xp too... i think ownerdraw needs in win98 only :hz:
The reason we didn't go that route is that it doesn't properly support alpha transparency. Plus, when you hover the items, the icon is inverted (an extremely ugly, pointless design decision on MS's part).
To sum up: it was a design choice. We wanted the menus in wyBuild to be as usable and beautiful as possible while still matching the style of the base operating system.
Thanks for this, it works very well. Great Job!
Is there a way to make a MenuItem bold? Or did i miss something?
Set it as the default item and it becomes bold.
you're really a good webmaster. The web site loading speed is amazing. It seems that you are doing any unique trick. Furthermore, The contents are masterpiece. you have done a wonderful job on this topic!
Extremely neat article. Neat.