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

Use Part of the Main Menu for a Context Menu

Problem

You want to create a context menu that shows the same entries as part of an application main menu.

Solution

Use the CloneMenu method to duplicate a portion of the main menu.

Discussion

In many applications, a control’s context-sensitive menu duplicates a portion of the main menu. Unlike Visual Basic 6, .NET differentiates between context menus and main menus, and a menu item can only belong to one menu at a time.

The solution is to make a duplicate copy of a portion of the menu using the CloneMenu method. The CloneMenu method not only copies the appropriate MenuItem items (and any contained submenus), it also registers the MenuItem with the same event handlers. Thus, when a user clicks a cloned menu ...

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