2017-04-14 30 views
0

删除CustomTaskPane对于插件对于超出期待一个新的自定义任务窗格被添加到一个特定的窗口使用下面的代码:从窗口

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

现在我希望能够再次关闭这个customTaskpane的具体窗口,我搜索了很多,很不幸没有成功。
我无法在活动窗口中找到任务窗格。我试过寻找一些窗口的唯一ID或者链接到字典的东西,并且用这种方法关闭它,也没有任何运气。
任何人都可以帮助我或指出我的好方向吗?

回答

0

您可以使用CustomTaskPanes类的RemoveRemoveAt方法。

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); 
     } 
    } 
    } 

此外,您可能会考虑使用Visible属性隐藏窗格。

阅读更多关于Managing Task Panes in Multiple Word and InfoPath Documents文章中的可能选项。

+0

这种方法的问题是,它隐藏了每个窗口上的所有CustomTaskPanes,我只想在特定的窗口上关闭它。 – Ben