Thursday, February 15, 2007 8:02 PM
timpash
Custom Task Panes in InfoPath 2007 Using VB.NET
Folks,
Just starting to get involved in dealing with VB.NET and VSTA in InfoPath 2007. A lot of what I've taken for granted in InfoPath 2003 and JScript no longer applies. Take Custom Task Panes for example. A neat idea, and super-useful. Doesn't work the same way in InfoPath 2007. Well some of it does. For example, the format of the typical html file that you would use as a resource file for the task pane is formatted the same. For those of you that haven't built one before, you'll copy and paste this into "mission-critcal notepad" and edit from there. Here is a sample:
<html>
<body>
<font face="arial" color="black">
<div id="fieldname1" style="display:none">
<p><font color="blue"><b>KO Title</b></font></p>
<br />
Your text will appear here in the task pane.
<br>
</div>
<div id="fieldname2" style="display:none">
<p><font color="blue"><b>KO Type</b></font></p>
<br />
Your different text will appear here in the task pane.
</div>
</font>
</body>
</html>
The idea is that you have a div statement that separates what content to show when. In InfoPath 2007, you'll go to the programming choices off the menu and choose Context Changed Event. This will put an event handler in place and stub out the code you need. Here is the code that works for me:
Private helpString As String
Public Sub FormEvents_ContextChanged(ByVal sender As Object, ByVal e As ContextChangedEventArgs)
Try
If (e.ChangeType = "ContextNode") Then
' The XML selection or context has changed.
'Retrieve task pane object
Dim customTaskPane As HtmlTaskPane = Me.CurrentView.Window.TaskPanes.Item(0)
'Get the collection of html elements in the task pane.
Dim htmlDocument As mshtml.HTMLDocument = customTaskPane.HtmlDocument
Dim htmlDocumentAll As IHTMLElementCollection = htmlDocument.all
'Clear previous help topic from task pane
If Not String.IsNullOrEmpty(helpString) Then
'Get the first div that matches the helpString.
Dim htmlOldDivElem As mshtml.HTMLDivElement = htmlDocumentAll.item(helpString, 0)
htmlOldDivElem.style.display =
"none"
End If
'Keep record of string to be displayed, so it can later be cleared
helpString = e.Context.Name
'Get the first div that matches the helpString.
Dim htmlDivElem As mshtml.HTMLDivElement = htmlDocumentAll.item(helpString, 0)
If Nothing Is htmlDivElem Then
'No known context node.
helpString =
Nothing
Else
'Display DIV statement having same ID as the context node name
htmlDivElem.style.display =
String.Empty
Return
End If
End If
Catch exn As Exception
MessageBox.Show(exn.ToString())
End Try
End Sub
I assume that you know how to tell the form to use a Custom Task Pane and to upload the html file you built previously as a resource file and associate it with the Custom Task Pane. The only thing that sucks about this is that the form requires full trust with a level 2 code signing cert. I've self-signed my form for now, but am hoping to get a resolution to that. At least InfoPath 2007 doesn't completely shut you down when it sees an untrusted cert like InfoPath 2003 did.