Pieter van der Westhuizen

Outlook context sensitivity: show custom UI for certain folders and items types

Add-in Express makes it possible to display your custom UI elements based on various Outlook components. Elements such as toolbars, toolbar controls, ribbon tabs, ribbon tab controls or Advanced Form Regions can be hidden or displayed based on what the user is doing in Outlook at any given moment. By using Add-in Express’ implementation of these UI elements, developers can control what interfaces to show based on the folder content and/or the various Outlook item types (Mail, Appointment, Contact, etc.).

In this post, I’ll demonstrate how to use this powerful feature in a Microsoft Outlook add-in created using Add-in Express. Start by creating an Add-in Express COM Add-in project.

Creating a new ADX COM Add-in Project in Visual Studio 2010

Select your preferred programming language (C#, VB.NET, C++.NET) and the Minimum supported Office version. Add-in Express enables you to develop for all versions of Microsoft Office in one Visual Studio project i.e. one code base for Office 2000 up to Office 2010!

Selecting a preferred programming language

Select which Microsoft Office applications will be supported by the add-in. Add-in Express allows you to write an add-in that can be shared amongst all Microsoft Office applications.

Selecting Microsoft Office applications to be supported by the add-in

Next, we add the following components:

  • ADXOlExplorerCommandBar
  • ADXOlInspectorCommandBar
  • ADXRibbonTab
  • ADXOutlookFormsManager
  • ADXMainMenu
  • ADXContextMenu

Adding components

Explorer command bar

The ExplorerCommandBar’s properties will look like this:

Adding components

When setting the FolderName property to Personal Folders\Northwind and the ItemTypes property to Mail, it will only show the commandbar when the Northwind folder is selected and the ItemTypes within that folder is mail items.

Using the Add-in Express designers, we can add a Combobox to the Commandbar and set its properties to the following:

Adding a Combobox to the Commandbar

Note the OlExplorerItemTypes property is set to Mail, and the OlItemTypeAction property to adxOlActionEnable. This will ensure that the ComboBox will only become enabled when the ItemTypes are mail items; this enables the developer to share one Commandbar between explorers and enable or show functionality depending on the selected item types.

Inspector command bar

If the requirement is that the user must have a Commandbar when opening an e-mail, you need the InspectorCommandBar component. Its properties will look like this:

InspectorCommandBar component properties

The design for the InspectorCommandBar as well as its properties will be similar as the above. This will ensure that when a user opens a mail item, they will see the CommandBar with the condition that the mail item is in the Personal Folders\Northwind folder.

Custom Outlook CommandBar

Outlook main menu

The ADXMainMenu component is used for versions of Office that do not use the Ribbon interface i.e. Office 2003, Office XP, Office 2000 and Outlook 2007 Explorer window.

As with commandbars, you can select in which Office application the main menu and context menu should be displayed, by setting its SupportedApp property.

MainMenu component properties

Each item on the ADXMainMenu and ADXContextMenu can also individually be set, by setting the OlItemTypeAction property to adxOlActionShow or adxOlActionEnabled, based on the either the Explorer or Inspector Item types specified in the ADXMainMenu’s OlExplorerItemTypes and OlInspectorItemTypes properties.

Specifying Explorer or Inspector Item types

Outlook folder property page

To add your own folder property page, all you need to do is select the AddinModule designer and click the ellipses(…) button of the FolderPages property. You can specify for which folder or folders the custom property page should be shown, by setting the FolderName or FolderNames properties.

Setting the FolderName properties

Ribbon tabs

Switching to Office 2007/2010, the only property we need to set on the RibbonTab is the Ribbons property:

Setting the Ribbons property

Setting it to OutlookExplorer and OutlookMailRead, it will show the Ribbontab on the Outlook main screen as well as when the user opens an e-mail.

Ribbon tab on the Outlook main screen

Advanced Outlook regions

Advanced Regions are another Add-in Express feature which you can set to be context-sensitive, by setting the Outlook Forms Manager items’ properties to the following:

Setting the Outlook Forms Manager items' properties

You will only show the form specified in the FormClassName property, in the BottomNavigationPane Advanced region, which is specified in the ExplorerLayout property, when the user has selected a folder with mail items as specified in the ExplorerItemTypes property. When any folder with another item type than mail items is selected, the advanced region will not be visible.

The great part is that all of this is accomplished without any code, but by simply setting the appropriate properties on the Outlook components.

Thank you for reading. Until next time, keep coding.

You may also be interested in:

Post a comment

Have any questions? Ask us right now!