O'Reilly logo

Visual Basic® .NET by Example by Bob Donald, Gabriel Oancea

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

Owner Drawn Menu Items

At some point, you may need the capability to create a menu item that has a custom look. For example, most Windows applications today contain menus that have cute little icons on the menu items. The default behavior of the MenuItem class does not have support for this. However, you can write code to do this yourself. This concept is called owner drawing.

Instead of having the MenuItem do all of the drawing, you can subclass MenuItem with your own class and override two methods for providing your own drawing routines. Here is example code that creates a subclass of MenuItem for the purposes of adding icons to menus. Create a new Windows application project and add this class to the project:

 Imports System Imports System.ComponentModel ...

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