Dela via


Customizing a Ribbon for InfoPath

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 application-level 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. For more information, see Switch form designing a form template to filling out a form.

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.

Specifying 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 ID's 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.

Specifying the Ribbon Type by Using Ribbon XML

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

The IRibbonExtensibility.GetCustomUI(String) 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 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
public string GetCustomUI(string ribbonID)
{
    string ribbonXML = String.Empty;

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

    return ribbonXML;
}

See Also

Concepts

Accessing the Ribbon at Run Time

Ribbon Designer

Ribbon XML

Other Resources

Ribbon Overview