Custom Task Pane

Jul 11, 2012 at 5:31 PM


Are there any samples or tutorials on creating custom task panes using the NetOffice API.


Jul 11, 2012 at 5:42 PM

a custom taskpane addin example is available for any office application.
please ceckout the latest 1.5.1 release in the download section.

for example, the .net 4.0 c# example for excel is here located:
NetOffice 1.5.1\NET 4.0\Examples\Excel\C#\COMAddin Examples\COMAddinTaskPaneExample


Jul 11, 2012 at 6:31 PM

Thanks. Exactly what I was looking for.

Is it possible for the user control within the pane to access properties of the custom task pane, for example to dynamically control the width of the pane at runtime?



Jul 11, 2012 at 7:03 PM

hello chris,

not by default but you can use a trick. we use the netoffice tutorial as example.

1.) define a public property in the sampleControl:
  public Office._CustomTaskPane TaskPane;

2.) modify the CTPFactoryAvailable method in Addin.cs

                Office._CustomTaskPane taskPane = ctpFactory.CreateCTP(typeof(Addin).Assembly.GetName().Name + ".SampleControl", "NetOffice Sample Pane(CS4)", Type.Missing);
                taskPane.DockPosition = MsoCTPDockPosition.msoCTPDockPositionRight;
                taskPane.Width = 300;
                taskPane.Visible = true;
                _sampleControl = taskPane.ContentControl as SampleControl;
                _sampleControl.TaskPane = taskPane;
                // ctpFactory.Dispose();

remove the last line and set _sampleControl.TaskPane. now you can set the width of the control dynamicly inside your control. something like this:

      private void button1_Click(object sender, EventArgs e)
            TaskPane.Width = 600;

Jul 13, 2012 at 10:38 AM

Thanks for your help with this. Since we are removing ctpFactory.Dispose(); is there another place in the code where it should be called?



Jul 13, 2012 at 9:57 PM


the ctpFactory object is a child from the hostapplication(excel, word, whatever you use)

you have to dispose the hostapplication in the IDTExtensibility2.OnDisconnection method


now, all childs from hostapplication are diposed too(recursiv) this means also ctpFactory of course.
any object in NetOffice implements the Dispose() method but yout dont need to dispose any object explictitly.
By calling Dispose() the element and all other elements created through it will be freed.

Documentation: COM Proxy Management in NetOffice