O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Create an Owner-Drawn Menu

Problem

You want to create a menu that includes pictures, formatted text, or colored item backgrounds.

Solution

Set the OwnerDraw property to True for each MenuItem control you want to draw, and handle the MeasureItem and DrawItem events.

Discussion

The MenuItem class that is included with the .NET Framework is fairly limited. It doesn’t provide any ability to change menu font, colors, or even add the common thumbnail icon. To add any of these enhancements, you’ll need to combine your menu with custom drawing logic.

Fortunately, .NET makes it easy to replace the standard drawing logic with your own custom code. All you need to do is set the OwnerDraw property for a MenuItem to True. A context menu or main menu can contain ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required