C# 多窗口中的PowerPoint 2010自定义任务窗格

C# 多窗口中的PowerPoint 2010自定义任务窗格,c#,.net,vsto,powerpoint,office-addins,C#,.net,Vsto,Powerpoint,Office Addins,我正在为Microsoft PowerPoint 2010开发自定义任务窗格。我需要在多个应用程序窗口/演示文稿之间同步任务窗格。使用功能区上的切换按钮显示任务窗格 由于PowerPoint 2010在不同的文档窗口中显示每个演示文稿(与2007不同),因此我需要为每个窗口分别创建一个任务窗格并同步它们。我遵循了关于如何为多个应用程序窗口创建任务窗格的说明,并使用该方法指定任务窗格应与哪个应用程序窗口关联。在这种情况下,对象是任务窗格应关联的PowerPoint.DocumentWindow 由

我正在为Microsoft PowerPoint 2010开发自定义任务窗格。我需要在多个应用程序窗口/演示文稿之间同步任务窗格。使用功能区上的切换按钮显示任务窗格

由于PowerPoint 2010在不同的文档窗口中显示每个演示文稿(与2007不同),因此我需要为每个窗口分别创建一个任务窗格并同步它们。我遵循了关于如何为多个应用程序窗口创建任务窗格的说明,并使用该方法指定任务窗格应与哪个应用程序窗口关联。在这种情况下,
对象
是任务窗格应关联的
PowerPoint.DocumentWindow

由于某些原因,我的所有任务窗格都是在活动窗口中创建的,而不是在我指定的窗口中创建的。例如,如果我打开3个PowerPoint演示文稿,然后切换任务窗格,则所有三个任务窗格都将添加到活动窗口中

这是我在按下切换按钮时用于添加任务窗格的代码:

public void AddAllTaskPanes()
{
   PowerPoint.DocumentWindows windows = Globals.ThisAddIn.Application.Windows;
   if(windows.Count > 0)
   {
      for (int i=1; i<=windows.Count; i++){
         PowerPoint.DocumentWindow window = windows[i];
         customTaskPane = this.CustomTaskPanes.Add(new UserControl1(), "My User Control", window);
         customTaskPane.Visible = true;
      }
   }
}
public void AddAllTaskPanes()
{
PowerPoint.DocumentWindows windows=Globals.ThisAddIn.Application.windows;
如果(windows.Count>0)
{

对于(int i=1;i我采用了从PresentationAfterOpen和PresentationAfterNew事件创建任务窗格的方法,这两个事件会产生相同的行为

关于PresentationAfterOpen事件的说明,如果用户选择的文档已打开,则事件仍会激发,因此在创建新文档之前,您需要检查是否已为该文档创建CustomTaskPane

解决此问题的一种方法是在CustomPane中创建指向关联DocumentWindow的指针,并通过CustomTaskPaneCollection检查关联DocumentWindow枚举