Accessing custom task pane is active window - Visual Basic, VSTO

▼魔方 西西 提交于 2019-12-01 11:29:47

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!