Customize UI features by using extensibility interfaces

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

The Office development tools in Visual Studio provide classes and designers that handle many implementation details when you use them to create custom task panes, ribbon customizations, and Outlook form regions in a VSTO Add-in. However, you can also implement the extensibility interface for each feature yourself if you have special requirements.

Applies to: The information in this topic applies to VSTO Add-in projects. For more information, see Features available by Office application and project type.

Overview of extensibility interfaces

Microsoft Office defines a set of extensibility interfaces that COM VSTO Add-ins can implement to customize certain features, such as the ribbon. These interfaces provide full control over the features they provide access to. However, implementing these interfaces requires some knowledge of COM interoperability in managed code. In some cases, the programming model of these interfaces is also not intuitive for developers who are accustomed to the .NET Framework.

When you create a VSTO Add-in by using the Office project templates in Visual Studio, you do not have to implement the extensibility interfaces to customize features like the ribbon. The Visual Studio Tools for Office runtime implements these interfaces for you. Instead, you can use more intuitive classes and designers provided by Visual Studio. However, you can still implement the extensibility interfaces directly in your VSTO Add-in if you want to.

For more information about the classes and designers that Visual Studio provides for these features, see Custom task panes, Ribbon designer, and Create Outlook form regions.

Extensibility interfaces you can implement in a VSTO Add-in

The following table lists the extensibility interfaces you can implement and the applications that support them.

Interface Description Applications
IRibbonExtensibility Implement this interface to customize the ribbon UI. Note: You can add a Ribbon (XML) item to a project to generate a default IRibbonExtensibility implementation in your VSTO Add-in. For more information, see Ribbon XML. Excel

InfoPath 2013

InfoPath 2010

Outlook

PowerPoint

Project

Visio

Word
ICustomTaskPaneConsumer Implement this interface to create a custom task pane. Excel

Outlook

PowerPoint

Word
FormRegionStartup Implement this interface to create an Outlook form region. Outlook

There are several other extensibility interfaces that are defined by Microsoft Office, such as IBlogExtensibility, EncryptionProvider, and SignatureProvider. Visual Studio does not support implementing these interfaces in a VSTO Add-in created by using the Office project templates.

Use extensibility interfaces

To customize a UI feature by using an extensibility interface, implement the appropriate interface in your VSTO Add-in project. Then, override the RequestService method to return an instance of the class that implements the interface.

For a sample application that demonstrates how to implement the IRibbonExtensibility, ICustomTaskPaneConsumer, and FormRegionStartup interfaces in a VSTO Add-in for Outlook, see the UI Manager Sample in Office development samples.

Example of implementing an extensibility interface

The following code example demonstrates a simple implementation of the ICustomTaskPaneConsumer interface to create a custom task pane. This example defines two classes:

  • The TaskPaneHelper class implements ICustomTaskPaneConsumer to create and display a custom task pane.

  • The TaskPaneUI class provides the UI of the task pane. The attributes for the TaskPaneUI class make the class visible to COM, which enables Microsoft Office applications to discover the class. In this example, the UI is an empty UserControl, but you can add controls by modifying the code.

    Note

    To expose the TaskPaneUI class to COM, you must also set the Register for COM Interop property for the project.

    Public Class TaskPaneHelper
        Implements Office.ICustomTaskPaneConsumer
    
        Friend taskPane As Office.CustomTaskPane
    
        Public Sub CTPFactoryAvailable(ByVal CTPFactoryInst As Office.ICTPFactory) _
            Implements Office.ICustomTaskPaneConsumer.CTPFactoryAvailable
    
            If CTPFactoryInst IsNot Nothing Then
                ' Create a new task pane.
                taskPane = CTPFactoryInst.CreateCTP( _
                    "Microsoft.Samples.Vsto.VB.TaskPaneUI", "Contoso")
                taskPane.Visible = True
            End If
        End Sub
    End Class
    
    <System.Runtime.InteropServices.ComVisible(True)> _
    <System.Runtime.InteropServices.ProgId("Microsoft.Samples.Vsto.VB.TaskPaneUI")> _
    <System.Runtime.InteropServices.Guid("FFA0920E-F7A5-453d-8AB2-249F4C25B4B2")> _
    Public Class TaskPaneUI
        Inherits UserControl
    End Class
    
    public class TaskPaneHelper : Office.ICustomTaskPaneConsumer
    {
        internal Office.CustomTaskPane taskPane;
    
        public void CTPFactoryAvailable(Office.ICTPFactory CTPFactoryInst)
        {
            if (CTPFactoryInst != null)
            {
                // Create a new task pane.
                taskPane = CTPFactoryInst.CreateCTP(
                    "Microsoft.Samples.Vsto.CS.TaskPaneUI",
                    "Contoso");
                taskPane.Visible = true;
            }
        }
    }
    
    [System.Runtime.InteropServices.ComVisible(true)]
    [System.Runtime.InteropServices.ProgId("Microsoft.Samples.Vsto.CS.TaskPaneUI")]
    [System.Runtime.InteropServices.Guid("FFA0920E-F7A5-453d-8AB2-249F4C25B4B2")]
    public class TaskPaneUI : UserControl
    {
    }
    

    For more information about implementing ICustomTaskPaneConsumer, see Create custom task panes in the 2007 Office system in the Microsoft Office documentation.

Example of overriding the RequestService method

The following code example demonstrates how to override the RequestService method to return an instance of the TaskPaneHelper class from the previous code example. It checks the value of the serviceGuid parameter to determine which interface is being requested, and then returns an object that implements that interface.

Friend taskPaneHelper1 As TaskPaneHelper

Protected Overrides Function RequestService( _
    ByVal serviceGuid As Guid) As Object

    If (serviceGuid = GetType(Office.ICustomTaskPaneConsumer).GUID) Then
        If (taskPaneHelper1 Is Nothing) Then
            taskPaneHelper1 = New TaskPaneHelper()
        End If
        Return taskPaneHelper1
    End If

    Return MyBase.RequestService(serviceGuid)
End Function
internal TaskPaneHelper taskPaneHelper1;

protected override object RequestService(Guid serviceGuid)
{
    if (serviceGuid == typeof(Office.ICustomTaskPaneConsumer).GUID)
    {
        if (taskPaneHelper1 == null)
        {
            taskPaneHelper1 = new TaskPaneHelper();
        }
        return taskPaneHelper1;
    }

    return base.RequestService(serviceGuid);
}

See also