2016-01-08 67 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; 
} 
相關問題