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 ...

Get Visual Basic® .NET by Example now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.