Posts Tagged ‘ICustomTaskPaneConsumer’

C# .Net – How to capture a close button press on a Office Custom Task pane

April 27, 2011

When developing our office custom task pane we wanted to control whether pane was displayed when the office application started.

Initially we implemented a ribbon menu that toggled the panes visibility. When the user toggled the pane, we stored the visibility in the registry so that the next time the office application started we would only show the pane if it was required.

But, if the user closed the pane via its close button rather than the toggle button then we would not update the registry.

The solution was to update the registry when the pane visibility changed rather than when the toggle method is called.

There are a couple of events exposed on _CustomTaskPaneEvents_Event interface:

  1. DockPositionStateChange
  2. VisibleStateChange

The VisibleStateChange event is fired when ever the pane shows or is removed.

public void CTPFactoryAvailable( ICTPFactory CTPFactoryInst ) {
    CTP = CTPFactoryInst.CreateCTP(
        typeof( OfficeTaskPanelControl ).FullName,
        "Perfion", Type.Missing );

CTP.VisibleStateChange += CTP_VisibleStateChange;

    CTP.Visible = true;
    CTP.Width = 250;

void CTP_VisibleStateChange( CustomTaskPane CustomTaskPaneInst ) {
    // Update the registry at this point. RegHlp.Set("PanelVisibility", "" + CTP.Visible );