Bagikan melalui


Customizing UI Features By Using Extensibility Interfaces

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Application-level projects

Microsoft Office version

  • 2007 Microsoft Office system

For more information, see Features Available by Application and Project Type.

Visual Studio Tools for Office provides classes and designers that handle many implementation details when you use them to create custom task panes, Ribbon customizations, and Outlook form regions in an application-level add-in. However, you can also implement the extensibility interface for each feature yourself if you have special requirements.

Overview of Extensibility Interfaces

Applications in the 2007 Microsoft Office system define a set of extensibility interfaces that COM add-ins can implement to customize certain user interface (UI) features. Visual Studio Tools for Office simplifies this process by implementing these interfaces for you, and by providing classes and designers that you can use instead. However, you can also implement extensibility interfaces directly in your add-in.

For more information about the classes and designers that Visual Studio Tools for Office provides for these features, see Custom Task Panes Overview, Ribbon Designer, and Creating Outlook Form Regions.

Extensibility Interfaces You Can Implement in an Add-In

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

Interface

Description

Applications

Microsoft.Office.Core.IRibbonExtensibility

Implement this interface to customize the Ribbon UI. For more information, see IRibbonExtensibility Object in the 2007 Microsoft Office documentation.

Note

You can add a Ribbon (XML) item to a project to generate a default implementation of Microsoft.Office.Core.IRibbonExtensibility in your add-in. For more information, see Ribbon XML.

Excel 2007

InfoPath 2007

Outlook 2007

PowerPoint 2007

Word 2007

Microsoft.Office.Core.ICustomTaskPaneConsumer

Implement this interface to create a custom task pane. For more information, see ICustomTaskPaneConsumer Object in the 2007 Microsoft Office documentation.

Excel 2007

Outlook 2007

PowerPoint 2007

Word 2007

Microsoft.Office.Interop.Outlook.FormRegionStartup

Implement this interface to create an Outlook form region. For more information, see FormRegionStartup Interface in the 2007 Microsoft Office documentation.

Outlook 2007

There are several other extensibility interfaces that are defined by applications in the 2007 Microsoft Office system, such as Microsoft.Office.Core.IBlogExtensibility, Microsoft.Office.Core.EncryptionProvider, and Microsoft.Office.Core.SignatureProvider. Visual Studio Tools for Office does not support implementing these interfaces in an add-in.

Using Extensibility Interfaces

To customize a UI feature by using an extensibility interface, implement the appropriate interface in your 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 Microsoft.Office.Core.IRibbonExtensibility and Microsoft.Office.Core.ICustomTaskPaneConsumer interfaces in an add-in for Excel, see Runtime Services Sample.

Example of Implementing an Extensibility Interface

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

  • The TaskPaneHelper class implements Microsoft.Office.Core.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. For more information, see How to: Register a Component for COM Interop.

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", Type.Missing);
            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 Microsoft.Office.Core.ICustomTaskPaneConsumer, see Creating Custom Task Panes in the 2007 Office System in the 2007 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

Tasks

Runtime Services Sample

How to: Create Visual Studio Tools for Office Projects

Concepts

Programming Application-Level Add-Ins

Developing Office Solutions

AddIn Host Item

Calling Code in Application-Level Add-ins from Other Solutions

Architecture of Application-Level Add-Ins