Display a Custom Toolbar [InfoPath 2003 SDK Documentation]
- Microsoft Office InfoPath 2003
- Microsoft Office InfoPath 2003 Service Pack 1
The Customize dialog box allows you to create a custom toolbar in Microsoft Office InfoPath 2003, but you cannot add custom commands to the toolbar—you can add only built-in InfoPath commands. It is possible, however, to add a custom toolbar that contains custom commands to your InfoPath form.
To create a toolbar with custom commands, you must edit the form definition file (.xsf) associated with a given form. To be able to edit the .xsf file of a form, you must first extract the form files from your form. To extract the form files, open the form template (an .xsn file) in design mode, click Extract Form Files on the File menu, and then select a folder to which the form files will be extracted.
After you have extracted the form files, you can modify the .xsf file by using any text or XML editor, such as Microsoft Notepad.
Caution Edit .xsf files with care. If an invalid entry is made in an .xsf file, the form that the file is associated with may be left in an unusable state and you may have to correct the invalid entry before you can open the file in InfoPath.
You can create a custom toolbar by defining aelement as a child element of a element. The toolbar element contains two required attributes: and . The caption attribute is used as the title of the toolbar. The name attribute is used to identify the toolbar within a view.
Theelement is used to define buttons on the custom toolbar. The following table describes each attribute of a button element.
|No||Specifies an action of an editing component, using the syntax "NameOfEditingComponent::NameOfAction"|
|No||Provides the caption displayed on the button|
|No||Provides a Uniform Resource Locator (URL) to a bitmap (.bmp) or graphics interchange format (.gif) file, which is used for the button or menu item|
|No||Used to associate the OnClick event handler of the button with a scripting function|
|No||Specifies the editing context of the button|
|No||Provides the ScreenTip text to be used for the button|
|No||Specifies the name of anelement, for which the button is used|
The following example defines a toolbar named Sales Report, which contains three buttons. To associate script with these buttons, you must create an event handler that handles the OnClick event for each button.
<xsf:toolbar caption="Sales Report" name="Sales Report"> <xsf:button name="SalesByRegion" caption="Sales by Region"></xsf:button> <xsf:button name="SalesByMonth" caption="Sales by Month"></xsf:button> <xsf:button name="SalesByEmp" caption="Sales by Employee"></xsf:button> </xsf:toolbar>
You can use theelement to create a drop-down menu on your custom toolbar. The following table describes the elements and attributes of a menu element.
|No||Defines a button that has an associated action|
|Yes||Used as the caption for a menu|
|No||Contains information about the menus used within a menu (cascading menus)|
Note To create cascading menus, a menu element can be nested inside another menu element.
The following example builds on the previous example by adding a drop-down menu with the caption Sales by Qtr to the toolbar. This menu contains four buttons. You must create an event handler for the OnClick event associated with each of these buttons for them to be functional.
<xsf:toolbar caption="Sales Report" name="Sales Report"> <xsf:button name="SalesByRegion" caption="Sales by Region"></xsf:button> <xsf:button name="SalesByMonth" caption="Sales by Region"></xsf:button> <xsf:button name="SalesByEmp" caption="Sales by Employee"></xsf:button> <xsf:menu caption="Sales by Qtr"> <xsf:button name="Q1Sales" caption="Q1 Sales"></xsf:button> <xsf:button name="Q2Sales" caption="Q2 Sales"></xsf:button> <xsf:button name="Q3Sales" caption="Q3 Sales"></xsf:button> <xsf:button name="Q4Sales" caption="Q4 Sales"></xsf:button> </xsf:menu> </xsf:toolbar>
Note A complete reference to the .xsf file, including all of its elements, attributes, and other entities, can be found in the InfoPath XSF Reference that is part of theand the Microsoft Script Editor (MSE) Help system.