With all the wonderful features in the new office apps, it's easy to get lost! Infopath is no exception, and when you make clever use of the new features, you'll want to make sure that users understand how your form is supposed to work. wouldn't it be great if you cocould display contextual help information as the user navigates to fields in your form. with the "context changed" event, you can execute custom code when the user filling the form causes the context node to change. this will fire when the user focuses a control bound to a different Dom node than the current context node.
Files you'll need
The solution we provide here uses some resource files. Download the attached files to accomplish the scenario.
1. "customtaskpanehelp.htm"-the HTML file that will be displayed in the custom task pane. we will manipulate this document at runtime from custom form code to display the contextually appropriate help information. just update the styles in this file to change the appearance of the contextual help in the Custom taskpane.
2. "Help strings. XML "-this file is a basic XML file that contains ings from local node names to the title and help contents for the node. this file will be consulted to retrieve the help information to be displayed in the custom task pane.
3. "customtaskpane. cs"-This helper class wraps the htmltaskpane object to access elements in the custom task pane. This will be added to your vsta project.
4. "formcode. cs"-this contains the code to integrate the custom taskpane into the form template.
Note that this method works in infopath 2003 and 2007, but this tutorial will walk you through the steps in for infopath 2007-the UI is slightly different in 2003, but you can still make it work. since task panes are a rich-client only feature, this method is not supported in browser-enabled form templates.
Construct your help resource file
Assuming you 've designed your form template already, you'll have a nicely populated data source, replete with variously named nodes. now add contextual help data for nodes in the main and secondary data sources:
1. Open the "Help strings. xml" file in Notepad (or another text editor .)
2. Add a "help" element for the data source node:
- Set the "nodename" attribute's value to "<node prefix >:< name in data source pane>"
- Set the "title" element's value to the heading that you want to display for this node's contextual help.
- Set the "contents" element's value to the body of this node's contextual help.
3. Repeat Step 2 for all nodes for which you want to display contextual help so that you have something like this:
<? XML version = "1.0" encoding = "UTF-8"?>
<Helpstrings>
<Helpstring>
<Help nodename = "My: textfield">
<Title> text field </title>
<Contents> help for my text field. </contents>
</Help>
<Help nodename = "My: richtextfield">
<Title> Rich Text Field </title>
<Contents> help for my rich text field. </contents>
</Help>
</Helpstring>
</Helpstrings>
4. Save the file to a shared location
Note: If you want to be able to update this help data without having to re-deploy the form template, the shared location shoshould be accessible to all users that will fill out the form. if, on the other hand, you do not care about that, then you can just save the file locally and add it as a resource file to the form template. see below...
Add the data source that will provide your contextual help data
Now that you're help strings are all set, we need to add a reference to the help strings so that the form template can access them. we'll do this by adding a data connection to query the XML file from a shared location or resource file.
1. Tools> data connections> Add
2. Select receive data, then XML document
3. specify the location of the help strings document (help strings. XML)
- If, as noted above, you want to include the help strings as a resource file in the form template, just click "next> ". including the file as a resource file guarantees that it will always be accessible to the form template, but the form template will have to be updated if you need to change the help strings.
- If, on the other hand, you wowould like to access the help strings file from a shared network location or web server, then select "access the data from the specified location" and then click "next> ". accessing the file from a shared location may fail if the shared location is unavailable, and there may be some delay due to network traffic.
4. Check the "automatically retrieve data when form is opened" check box and click "finish"/"close ".
Enable the custom task pane in your form template
Custom task panes are not enabled by default. We'll specify that the custom task pane shoshould be displayed, and its content shoshould be rendered from the "mtmtaskpanehelp.htm" file.
1. Tools> form Options> Programming
2. Check the "enable custom task pane" check box. Type a name for the custom task pane in the "task pane name" field.
3. Add the "mtmtaskpanehelp.htm" file as a resource file.
- Click resource files> Add...
- Browse to the "mtmtaskpanehelp.htm" file and click Open/OK.
4. Select "mtmtaskpanehelp.htm" from the "task pane location" drop-down list.
Add the code to manage the Context Change and display the contextual help information
1. Tools> programming> context changed event; this will create the vsta project and insert the "context changed" event handler.
2. Add the "mtmtaskpane. cs" file to your project
- Right-click the top-level project node.
- Click "add"> "existing item... "
- Browse to the "mtmtaskpane. cs" file and click "add ".
- Important: Edit the namespace of the "mtmtaskpane. cs" file to be the same as that of your form code file.
3. integrate the code in the attached "formcode. CS "file into your vsta project. make sure you copy the contents of the "formevents_contextchanged" method, as well as the private properties and variables.
4. Build and save your form template.
Make the form template full trust
- Tools> form Options> security and trust
- Uncheck the "automatically determine security level" checkbox. Select the "full trust" radio button.
- Click "OK"
- Save and publish the form template. You will need to publish the form template as an installable form template (. MSI) or digitally sign the template; detailed instructions are here.
Now, when users fill out your form, contextual help will be displayed for each node as the user clicks on a control bound to it. as long as you 've got ded help information in the Help strings file, you'll see the help information in your custom task pane!
Forrest dillaway
Software Design Engineer in Test
Filed under: writing code, controls
Attachment (s ):Contextualhelp.zip