0

For an addin for out look a new Custom task pane is added to a specific window using the following code:

historyPane = new HistoryPane(taskId);
customTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(historyPane, title, new Microsoft.Office.Interop.Outlook.Application().ActiveWindow());

Now I want to be able to close this customTaskpane again for the specific window, I've searched far and wide, unfortunately without any success.
I am unable to find a task pane in an active window. I've tried looking for some unique ID for a window or something to link to a dictionary and close it this way, also without any luck.
Would anyone be able to help me or point me in the good direction?

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Ben
  • 166
  • 2
  • 19

1 Answers1

-1

You can use the Remove or RemoveAt methods of the CustomTaskPanes class.

public void RemoveTaskPaneWithTitle()
{
    for (int i = this.CustomTaskPanes.Count; i > 0; i--)
    {
        ctp = this.CustomTaskPanes[i - 1];
        if (ctp.Title == "Your title")
        {
             this.CustomTaskPanes.RemoveAt(i - 1);
        }
     }
  }

Also you may consider hiding the pane using the Visible property.

Read more about possible options in the Managing Task Panes in Multiple Word and InfoPath Documents article.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • The problem with this method is that it hides all CustomTaskPanes on every window, where I just want to close it on a specific window. – Ben Apr 18 '17 at 06:03
  • You can associate a custom task pane instance with a window handle (ID), so you could recognize which one must be closed. – Eugene Astafiev Aug 02 '23 at 14:47