
Chapter 13: Extending Visual Studio 2010 | 389 |
Within the CommandBars collection, menuBarCommandBar, you then look into the Controls collection, which is a list of menus on the main menu to find the Tools menu, assigned to toolsControl as follows:
C#:
string toolsMenuName = "Tools"; CommandBarControl toolsControl =
menuBarCommandBar.Controls[toolsMenuName];
VB:
Dim toolsMenuName As String = "Tools" Dim toolsControl As CommandBarControl =
menuBarCommandBar.Controls.Item(toolsMenuName)
In the VS automation object model, an individual menu is a CommandBarPopup, assigned to toolsPopup as follows:
C#:
CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;
VB:
Dim toolsPopup As CommandBarPopup =
CType(toolsControl, CommandBarPopup)
Now you have a reference to the menu where the menu item for the
C#:
Command command = commands.AddNamedCommand2( _addInInstance, "KeystrokeFinder", "KeystrokeFinder",
"Executes the command for KeystrokeFinder",