在活动窗口中访问自定义任务窗格 - Visual Basic、VSTO [英] Accessing custom task pane in active window - Visual Basic, VSTO

查看:59
本文介绍了在活动窗口中访问自定义任务窗格 - Visual Basic、VSTO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 VSTO 中为 Ppt 2013 创建 COM 加载项,但在引用活动窗口中的自定义任务窗格时遇到问题.

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.

我的代码是:

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)

推荐答案

我进行了一个小实验,结果表明 CustomTaskPane.Window 始终是 ActiveWindow.因此,要解决此问题,您可以在某些字典中继续跟踪 Tackpanes:

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

以后你可以使用它:

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

这篇关于在活动窗口中访问自定义任务窗格 - Visual Basic、VSTO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆