Creating Office commandbar controls:
button, pop-up, context menu for Outlook, Excel, Word
Add-in Express™ Add-in Express Home > Add-in Express for Office and .NET > Online Guide > Tips and notes > Commandbar and controls tips Commandbar / toolbar tipsBelow we describe some important issues that you will probably run into when dealing with an Office commandbar (also referred to as toolbars), menus, their controls and menu items in Outlook, Excel, Word and other MS Office applications using Add-in Express .NET in VB.NET, C# or C++. To find more about advanced options and features that Add-in Express offers for customizing Office toolbars with .NET controls, please see a sample project showing how to add custom .NET control to Outlook toolbar.
Command bar terminologyIn the Add-in Express Guide, elsewhere on the Add-in Express site, and in all our documents we use the terminology suggested by Microsoft for all toolbars, their controls, and for all interfaces of the Office Type Library. For example:
According to object model references, a pop-up control is a built-in or custom control on a menu bar or toolbar that displays a menu when clicked, or a built-in or custom menu item on a menu, submenu, or shortcut menu that displays a submenu when the pointer is positioned over it. Pop-up button samples are View and View | Toolbars in the main menu and Draw in the Drawing toolbar in Word or Excel. ControlTag vs. Tag propertyAdd-in Express identifies all its controls (commandbar controls) through the use of the ControlTag property which is mapped to the Tag property of the CommandBarControl interface. The value of this property is generated automatically and you don't need to change it. For your own needs, use the Tag property instead. Pop-upsAccording to the Microsoft's terminology, the term "pop-up" can be used for several controls: pop-up menu, pop-up button, and submenu. With Add-in Express, you can create a pop-up as using the Controls property of a command bar and then add any control to the pop-up via the Controls property of the pop-up. However, pop-ups have an annoying feature: if an edit box or a combo box is added to a pop-up, their events are fired very oddly. Please don't regard this bug as that of Add-in Express. Built-in Office controls and command barsYou can connect an ADXCommandBar instance to any Office built-in commandbar. For example, you can add your own controls to the "Standard" commandbar or remove some controls from it. To do this just add to the add-in module a new ADXCommandBar instance and specify the name of the built-in command bar you need via the CommandBarName property. Also, you can add any built-in controls to your own commandbar. To do this just add an ADXCommandBarControl instance to the ADXCommandBar.Controls collection and specify the Id of the built-in control you need via the Id property. To find out the built-in control IDs, use the free Built-in Controls Scanner utility. How to make a command bar show up in some or all supported host applicationsUse the CommandBar.SupportedApps property to specify if the command bar is to appear in some or all host applications supported by the add-in. Unregister your add-in before you change the value of this property. Removing custom command bars and controlsAdd-in Express removes custom command bar(s) and controls when the add-in is uninstalled. However, this doesn't apply to Outlook and Access add-ins. You should set the Temporary property of custom command bars (and controls) to true to notify the host application that it can remove them itself. If you need to remove an Office commandbar or a button yourself, use the Tools | Customize dialog. See also Custom actions when your COM Add-in is uninstalled. How to display CommandBar as a popup (context) menuUse CommandBar.Position = adxMsoBarPopup option to display the CommandBar as a popup (context) menu. In the appropriate event handler, you write the following code:
The same applies to other command bar types. Built-in and custom command bars in Ribbon-enabled Office applicationsDo you know, that all usual command bars that we used in earlier Office versions are still alive in Office 2007-2013 applications ( an exception is Outlook 2013)? Our free Built-in Controls Scanner reports that, say, Outlook 2007 email inspector still has the Standard toolbar with the Send button on it. This may be useful if the functionality of your add-in takes into account if this or that toolbar button is enabled or disabled. As to custom toolbars, you can use set the UseForRibbon property of the corresponding component to true (the default value is false). This will result in your command bar controls showing up on the Add-ins tab along with command bar controls from other add-ins. Transparent icon on a CommandBarButtonIt looks like the ImageList has a bug: when you add images and then set the TransparentColor property, it corrupts the images in some way. Follow the steps below (at design-time) to get your images transparent:
Navigating up and down the command bar systemIt is easy to navigate down the command bar system: the host application supplies you with the Office.CommandBars interface that provides the Controls property returning a collection of the Office.CommandBarControls type. Office.CommandBarPopup provides the Controls property, too. When navigating up the command bar system, you use the Parent property of the current object. For a command bar control (see Commandbar terminology) , this property returns Office.CommandBar. Note that the same applies to controls on a pop-up; command bars returned in this way aren't listed anywhere else in the command bar system. The parent for an Office.CommandBar is the host application. The parent for an Outlook command bar is either Outlook.Inspector or Outlook.Explorer. Hiding and showing Outlook command barsADXOlExplorerCommandBar and ADXOlInspectorCommandBar implement context-sensitive command bars; when the current folder correspond to the components' settings, the corresponding command bar is shown. To "manually" hide or show an inspector comand bar, you handle the InspectorActivate event of the Outlook Application Events component (ADXOutlookAppEvents) and set the Visible property of the ADXOlInspectorCommandBar to an appropriate value. Explorer command bars are handled in the ExplorerFolderSwitch event (see ADXOutlookAppEvents). One thing to remember: you need to set ADXOlExplorerCommandBar.Enabled to true before you change ADXOlExplorerCommandBar.Visible to true. To hide an Outlook command bar "forever", you set the FolderName property of the corresponding command bar component so that it never matches any Outlook folder name. Useful resourcesIf you didn't find the answer to your questions on this page, please see the HOWTOs section: |