2016-01-08 68 views
2

我在VSTO中为Ppt 2013创建COM加载项,并且在活动窗口中引用自定义任务窗格时出现问题。访问自定义任务窗格是活动窗口 - Visual Basic,VSTO

我的代码应该使自定义任务窗格仅对活动窗口可见,但它当前对所有文档窗口都运行。

我的代码是:

For Each CTP As Microsoft.Office.Tools.CustomTaskPane In Globals.ThisAddIn.CustomTaskPanes 

     If CTP.Window Is Globals.ThisAddIn.Application.ActiveWindow Then 
      CTP.Visible = True 
     End If 

    Next 

的taskpane被添加到/创建的每个新的演示文稿使用下面的代码

AddIn_control1 = New AddIn_control 
AddIn_taskpane = Me.CustomTaskPanes.add(AddIn_control1, "Add-in taskpane", Me.Application.ActiveWindow) 
+0

你能告诉你在那里创建taskpanes的代码?我想你创建了它们与活动窗口相关联。 –

+0

我已添加信息以显示如何创建我的任务面板 - 谢谢 –

回答

2

我做过一个小实验打开,原来CustomTaskPane.Window总是的ActiveWindow。因此,要解决它,你可以保持tackpanes的跟踪在一些字典:

Dictionary<CustomTaskPane, PowerPoint.Presentation> ctpDict = new Dictionary<CustomTaskPane, PowerPoint.Presentation>(); 
void Application_AfterNewPresentation(PowerPoint.Presentation Pres) { 
    AddIn_control AddIn_control1 = new AddIn_control(); 
    CustomTaskPane AddIn_taskpane = this.CustomTaskPanes.Add(AddIn_control1, "Add-In Taskpane", this.Application.ActiveWindow); 
    ctpDict.Add(AddIn_taskpane, Pres); 
} 

,以后你可以用它:

if (cptDict[CTP] == Globals.ThisAddIn.Application.ActivePresentation) { 
    CTP.Visible = true; 
} 
相关问题