Creating toolbar menus that work with the ToolbarControl


Purpose
This sample demonstrates creating menu items, submenus, and pop-up menus using the ToolbarMenu object. The sample uses the ToolbarControl in conjunction with the MapControl and control commands.

How to use

See How to use ArcGIS samples for help on compiling, setting up the debugger, and running the sample. If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

  1. Browse to a map document to load into the MapControl.
  2. Navigate around the data using the commands on the ToolbarControl.
  3. Use the command buttons to add a menu item to the ToolbarControl, and a submenu to the menu item.
  4. Right-click the display to show the Navigation menu.

Additional information

The AddItem method is used within the Form_Load event to add new items to the ToolbarControl with their style set. An IMenuDef object is created from a menu defined within the same application. The menu is defined within a class implementing the IMenuDef interface and is made up of default ToolbarControl commands.
 
This menu is added to a ToolbarMenu using the AddItem method and the ToolbarMenu.Hook property is set to the ToolbarControl. A submenu is added to this menu using the IToolbarMenu.AddSubMenu method. The IToolbarMenu.PopupMenu method is used within the MapControl OnMouseDown event to display the menu when the right mouse button is used.


AssemblyInfo.cs Assembly information.
ToolbarMenu.cs Form file.
NavigationMenu.cs Class file.
ToolbarSubMenu.cs Class file.
Download the C# files
AssemblyInfo.vb Assembly information.
ToolbarMenu.vb Form file.
NavigationMenu.vb Class file.
ToolbarSubMenu.vb Class file.
Download the VB.NET files

Download the files for all languages

See Also:

ToolbarControl class
IToolbarControl interface
IToolbarMenu interface
IMenuDef interface




Development licensing Deployment licensing
Engine Developer Kit Engine Runtime
ArcView
ArcEditor
ArcInfo