UI Manager Sample

Note

This sample runs only in Microsoft Office Outlook 2007.

This sample demonstrates how to customize the user interface (UI) of Microsoft Office Outlook 2007 by implementing extensibility interfaces in an add-in. This sample uses extensibility interfaces to create a Ribbon customization, a custom task pane, and a custom form region.

This sample also demonstrates one way to coordinate custom UI elements for a specific Inspector window. The code in this sample ensures that the Ribbon customization, custom task pane, and custom form region in an Inspector can correctly communicate with each other. They must communicate in a manner that is isolated from other instances of these custom UI elements that might be open in other Inspectors.

For example, the user might have several Inspectors open, each of which has a custom Ribbon, task pane, and form region. When the user interacts with one of these elements—for example, by clicking a button on the Ribbon—it can cause a change in another element—for example, hiding the task pane. The code must ensure that only the elements in the one Inspector are affected, and not other instances of these custom UI elements in other Inspectors.

This sample uses a set of classes that wrap Inspector and custom task pane objects to ensure that a new task pane is displayed with every task and e-mail message that the user opens. The sample also creates custom Ribbon buttons that can be used to hide or display the task pane in each task or e-mail message, and it displays a custom form region in each task. For more information about the structure of this sample, see Components of the UI Manager Sample.

Note

Although this sample uses extensibility interfaces to create a Ribbon customization, a custom task pane, and a form region, Visual Studio Tools for Office provides classes and designers that you can use instead. These classes and designers simplify the process of working with these features. For more information, see Ribbon DesignerCustom Task Panes Overview, and Creating Outlook Form Regions.

Security noteSecurity Note:

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To run this sample

  1. Press F5.

  2. In Outlook, create a new task.

  3. On the Ribbon of the task, click the Add-Ins tab.

  4. In the UI Manager group, click the TaskPane button.

    Verify that the SimpleControl task pane appears next to the task window.

  5. In the Show group, click the UIM button.

    Verify that the custom form region appears in the Reading Pane of the open task. The form region displays a list of coffee beans and a text box that contains the number of coffee orders that have been placed.

  6. Select one or more types of coffee beans in the form region.

    Verify that each type of coffee bean you select is added to the SimpleControl task pane.

  7. On the Ribbon, in the Add-in Services group, click the Send button.

    Verify that a new e-mail message is sent to the recipient someone@example.com, and the e-mail message contains all of the types of coffee beans that you selected in the form region.

    Because the e-mail message represents a coffee order, the number of placed orders on the form region is incremented.

Requirements

This sample requires the following applications:

  • Visual Studio Tools for Office.

  • Microsoft Office Outlook 2007.

Demonstrates

This sample demonstrates the following concepts:

  • Creating a Ribbon customization by implementing the Microsoft.Office.Core.IRibbonExtensibility interface in an add-in.

  • Creating a custom task pane by implementing the Microsoft.Office.Core.ICustomTaskPaneConsumer interface in an add-in.

  • Creating a custom form region by implementing the Microsoft.Office.Interop.Outlook.FormRegionStartup interface in an add-in.

  • Managing and synchronizing the Ribbon customization, custom task pane, and form region in different e-mail messages and tasks in Outlook.

Components of the UI Manager Sample

The sample solution includes two projects:

  • Microsoft.Samples.Vsto.UiManager is an add-in project for Outlook. This project contains the implementations of the extensibility interfaces, and other classes and files that support these implementations.

  • Microsoft.Samples.Vsto.AddinUtilities is a class library that includes UI management classes and interfaces that are used by the Outlook add-in project.

These projects provide components that implement the custom task pane, Ribbon customization, and form region, and also components that help to synchronize and manage these features.

UI Management Components

The following table describes the project files that provide code for the Ribbon customization.

File

Description

ThisAddIn.cs/vb

Contains the override of the RequestService method and code that creates a new custom task pane for every Inspector window. For more information about this method, see Customizing UI Features By Using Extensibility Interfaces.

UserInterfaceContainer.cs/vb

Defines the UserInterfaceContainer class. Each UserInterfaceContainer object manages the form region, task pane, and Ribbon customization for a single e-mail message or task.

UserInterfaceElements.cs/vb

Defines the UserInterfaceElements class. This maintains the collection of UserInterfaceContainter objects used by the add-in.

IFormRegionControls.cs/vb

IRibbonConnector.cs/vb

Defines interfaces that several classes in the Microsoft.Samples.Vsto.UiManager and Microsoft.Samples.Vsto.AddinUtilities projects use to communicate with each other.

Custom Task Pane Components

The following table describes the project files that provide code for the custom task pane.

File

Description

TaskPaneConnector.cs/vb

Defines the TaskPaneConnector class. This class implements the Microsoft.Office.Core.ICustomTaskPaneConsumer interface.

SimpleControl.cs/vb

Defines the UserControl that provides the UI of the custom task pane. This control has attributes that expose the control to COM.

Ribbon Components

The following table describes the project files that provide code for the Ribbon customization.

File

Description

RibbonConnector.cs/vb

Defines the RibbonConnector class. This class implements the Microsoft.Office.Core.IRibbonExtensibility interface.

SimpleRibbon.xml

TaskRibbon.xml

Contains the Ribbon XML strings that are returned by the GetCustomUI method of the Microsoft.Office.Core.IRibbonExtensibility interface implementation.

Form Region Components

The following table describes the project files that provide code for the custom form region that is displayed in task Inspectors.

File

Description

FormRegionConnector.cs/vb

Defines the FormRegionConnector class. This class implements the Microsoft.Office.Interop.Outlook.FormRegionStartup interface.

FormRegionControls.cs/vb

Defines a class that manages the controls on each form region instance.

PictureConverter.cs/vb

Converts an Image to an IPictureDisp that can be used to display an icon on a form region.

SimpleFormRegion.ofs

Defines the UI of the form region.

SimpleFormRegion.xml

Contains the manifest for the form region.

SimpleFormRegion.reg

Creates the registry entries that are required to load the form region.

See Also

Tasks

Task Pane Demo Sample

Concepts

Customizing UI Features By Using Extensibility Interfaces

Ribbon Designer

Custom Task Panes Overview

Managing Custom Task Panes in Multiple Application Windows

Other Resources

Document-Level Samples