Compartir a través de


Customize a Ribbon for InfoPath

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

When you customize the Ribbon in Microsoft Office InfoPath, you must consider where your custom Ribbon will appear in the application. InfoPath 2010 can display the Ribbon in the following three types of InfoPath application windows:

  • Windows that display a form template that is opened in design mode.

  • Windows that display a form that is based on a form template.

  • The Print Preview window.

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

    Users and designers open a form template in design mode to modify the appearance and layout of the template. Users open forms that are based in a form template to add content.

    The Print Preview window enables designers and users to preview the pages of a form or form template before they print them.

Note

The AddIns tab does not appear in the Print Preview window. If you want a custom tab to appear in the Print Preview window, make sure that the OfficeId property of the tab is not set to TabAddIns.

You must specify the Ribbon type of each window in which you want your Ribbon to appear.

Specify the Ribbon type in the Ribbon designer

If you are using the Ribbon (Visual Designer) item, click the RibbonType property of the Ribbon in the Properties window, and then select any of the Ribbon IDs described in the following table.

Ribbon ID Window in which the Ribbon will appear when you run the project
Microsoft.InfoPath.Designer Windows that display a form template that is opened in design mode.
Microsoft.InfoPath.Editor Windows that display a form that is based on a form template.
Microsoft.InfoPath.PrintPreview The Print Preview window.

You can add more than one Ribbon to a project. If more than one Ribbon share a Ribbon ID, override the CreateRibbonExtensibilityObject method in the ThisAddin class of your project to specify which Ribbon to display at run time. For more information, see Ribbon overview.

Specify the Ribbon type by using Ribbon XML

If you are using the Ribbon (XML) item, check the value of the ribbonID parameter in the GetCustomUI method and return the appropriate Ribbon.

The GetCustomUI method is automatically generated by Visual Studio in the Ribbon code file. The ribbonID parameter is a string that identifies the type of InfoPath window that is opening.

The following code example demonstrates how to display a custom Ribbon only in a window that displays a form template in design mode. The Ribbon to display is specified in the GetResourceText() method, which is generated in the Ribbon class. For more information about the Ribbon class, see Ribbon XML.

public string GetCustomUI(string ribbonID)
{
    string ribbonXML = String.Empty;

    if (ribbonID == "Microsoft.InfoPath.Designer")
    {
        ribbonXML = GetResourceText("MyInfoPathProject.Ribbon.xml");
    }

    return ribbonXML;
}
Public Function GetCustomUI(ByVal ribbonID As String) As String Implements Office.IRibbonExtensibility.GetCustomUI
    Dim ribbonXML As String = String.Empty

    If ribbonID = "Microsoft.InfoPath.Designer" Then
        ribbonXML = GetResourceText("MyInfoPathProject.Ribbon.xml")
    End If

    Return ribbonXML

End Function

See also