Thursday, March 29, 2007

Taskpanes: Moving, resizing and navigation

Have you ever had the idea to move your InfoPath 2003 taskpane to the bottom of your screen, to the left or the right?
A taskpane cannot be moved (in default cases), but by using customized Office code we can do it !

Move and resize task panes

using Microsoft.Office.Interop.InfoPath.SemiTrust;
using Microsoft.Office.Core;
using System.Reflection;

//The following function unwraps the CommandBars object so that the CommandBars object
//is easier to use in the code.
private CommandBars UnwrapCommandbarsObject(ObjectWrapper commandBarsWrapper)

//Get the System.Type object for the CommandBars wrapper object.
Type t = commandBarsWrapper.GetType().BaseType;

//Use the Type object to retrieve the InnerObject property of the wrapper.
CommandBars objCommandBars = (CommandBars)t.InvokeMember("InnerObject", BindingFlags.Public BindingFlags.NonPublic BindingFlags.Instance BindingFlags.GetProperty, null, commandBarsWrapper, null);

//Return the result.
return objCommandBars;

private void ButtonClickAction()
CommandBars objCommandBars = UnwrapCommandbarsObject( (ObjectWrapper) thisXDocument.View.Window.CommandBars);

CommandBar oCommandBar = objCommandBars["Task Pane"];
oCommandBar.Width = 600;


Navigate to website urls
HTMLTaskPane tp = (HTMLTaskPane)this.thisXDocument.View.Window.TaskPanes[0];
tp.Visible = true;

In InfoPath 2007 it would be:
HtmlTaskPane pane = (HtmlTaskPane)this.CurrentView.Window.TaskPanes[0];


  • You need full trust!
  • Add a reference to COM component -> Microsoft Office 11 Object Library


  • Changing the behaviour of your TaskPane at runtime, also effects InfoPath at design time !
    You can only undo the TaskPane customization by re-executing the reversed code.


No comments: