gpt4 book ai didi

C# VSTO-Powerpoint-TaskPanes 在单独的窗口中。

转载 作者:太空宇宙 更新时间:2023-11-03 11:25:09 25 4
gpt4 key购买 nike

我正在为我的公司创建一个 VSTO,遇到了一个有趣的问题,我需要一些帮助。我会尽力解释这一点。我现在设置了 AddIn,以便在启动时通过 Application.AfterNewPresentation 事件创建 2 个 customTaskPanes。以及根据功能区上切换按钮的用户输入隐藏/显示这些内容的能力。

现在,当我启动名为“Presentation1”的第一个 PowerPoint 2010 时,一切正常,我可以显示/隐藏 TaskPanes,一切都按应有的方式插入。现在,我打开了第二个名为“Presentation2”的模板(以帮助在此处保持清晰)一切再次正常运行,我可以显示/隐藏 TaskPanes 并且一切正常插入。如果我回到“Presentation1”,插入内容和一切功能都很好,但是当我隐藏/显示 TaskPanes 时,它会在“Presentation2”上隐藏/显示它们。如果我创建一个“Presentation3”同样的事情会发生但“Presentation1”和“Presentation2”控制“Presentation3”TaskPanes。如果我关闭“Presentation2”和“Presentation3”,“Presentation1”按钮根本不会显示/隐藏任何内容。

ThisAddIn 中的代码

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Application.AfterNewPresentation += new PowerPoint.EApplication_AfterNewPresentationEventHandler(Application_AfterNewPresentation);
}

private void Application_AfterNewPresentation(PowerPoint.Presentation Pres)
{
PowerPoint.Application app = Pres.Application;
PowerPoint.DocumentWindow docWin = null;
foreach (PowerPoint.DocumentWindow win in Globals.ThisAddIn.Application.Windows)
{
if (win.Presentation.Name == app.ActivePresentation.Name)
{
docWin = win;
}
}

this.myWebForm = new SearchWebForm();
this.myWebFormTaskPane = this.CustomTaskPanes.Add(myWebForm, "Search ",docWin);
this.myWebFormTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
this.myWebFormTaskPane.Width = 345;
this.myWebFormTaskPane.VisibleChanged += new EventHandler(WebFormTaskPane_VisibleChanged);
}

private void WebFormTaskPane_VisibleChanged(object sender, System.EventArgs e)
{
Globals.Ribbons.Ribbon1.searchButton.Checked = myWebFormTaskPane.Visible;
if (Globals.Ribbons.Ribbon1.searchButton.Checked == true)
{
myWebForm.SearchForm_Navigate();
}
}

然后这是功能区

    private void searchButton_Click(object sender, RibbonControlEventArgs e)
{
Globals.ThisAddIn.WebFormTaskPane.Visible = ((RibbonToggleButton)sender).Checked;
}

最佳答案

在 PowerPoint 2007 中,自定义 task panes are shared across all presentation windows .如果您想为每个演示文稿分配单独的任务 Pane ,您需要处理相应的事件(WindowActivatePresentationClose 等)。您还需要管理您创建的所有任务 Pane 的列表,以便您可以显示/隐藏适当的任务 Pane 。这实际上是一个 well-known Outlook pattern frequently referred to in VSTO-world as InspectorWrappers - 或者在您的情况下是 DocumentWindowWrapper

这已针对 Powerpoint 2010 进行了更改,现在每个任务 Pane 都与特定窗口相关联。参见 this article .

您的错误是 Globals.ThisAddIn.WebFormTaskPane 不一定对应于当前的演示文稿任务 Pane - 您需要在托管列表中查找正确的任务 Pane (如上所述)。当您创建一个新任务 Pane (AfterNewPresentation) 时,将其添加到您的 CustomTaskPane收集并提供检索它的方法。

public partial class ThisAddIn
{
private Dictionary<PowerPoint.DocumentWindow, DocumentWindowWrapper> pptWrappersValue =
new Dictionary<PowerPoint.DocumentWindow, DocumentWindowWrapper>();
}

关于C# VSTO-Powerpoint-TaskPanes 在单独的窗口中。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9625466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com