2
votes

I'm creating a COM add-in in VSTO for Ppt 2013 and am having a problem referencing the custom task pane in the active window.

My code is supposed to make the custom task pane visible for the active window only, however it currently runs for all document windows.

My code is:

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

The taskpane is added to each new presentation created/ opened using the below code

AddIn_control1 = New AddIn_control
AddIn_taskpane = Me.CustomTaskPanes.add(AddIn_control1, "Add-in taskpane", Me.Application.ActiveWindow)
1
Can you show the code where you create your taskpanes? I guess you created them associated with the active window.Alex Butenko
I have added information to show how I am creating my taskpane - thanksJess_SK

1 Answers

6
votes

I conducted a little experiment and turns out CustomTaskPane.Window is always ActiveWindow. So to workaround it you can keep tracking of tackpanes in some dictionary:

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

and later you can use it:

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