C# VSTO-Powerpoint-TaskPanes 在单独的窗口中. [英] C# VSTO-Powerpoint-TaskPanes in separate windows.

查看:40
本文介绍了C# VSTO-Powerpoint-TaskPanes 在单独的窗口中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的公司创建一个 VSTO,并且遇到了一个我可以寻求帮助的有趣问题.我会尽力解释这一点.我现在已经设置了 AddIn,它可以在通过 Application.AfterNewPresentation 事件启动时创建 2 个 customTaskPanes.并且能够根据来自功能区上的切换按钮的用户输入来隐藏/显示这些.

I'm creating a VSTO for my company, and have ran across a interesting issue that I could use some help with. I will try to explain this to the best of my ability. I have the AddIn set up right now for it to create 2 customTaskPanes upon start up via Application.AfterNewPresentation events. And the ability to hide/show these based on user input from togglebuttons on the Ribbon.

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

Now when I fire up the first PowerPoint 2010 called "Presentation1" everything works great, I can show/hide the TaskPanes and everything inserts the way it should. Now then I open up a second template called "Presentation2"(to help keep things straight here) Everything works great again, I can show/hide the TaskPanes and everything inserts fine. If I go back to "Presentation1" the inserts and everything functions fine, but when I got to hide/show the TaskPanes it hides/shows them on "Presentation2". And if I create a "Presentation3" the same thing will happen but both "Presentation1" and "Presentation2" control "Presentation3" TaskPanes. And if I close the "Presentation2" and "Presentation3" the "Presentation1" buttons do not show/hide anything at all.

ThisAddIn 中的代码

Code in the 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 中,自定义 任务窗格在所有演示窗口中共享.如果您想为每个演示文稿分配单独的任务窗格,您需要处理相应的事件(WindowActivatePresentationClose 等).您还需要管理您创建的所有任务窗格的列表,以便您可以显示/隐藏适当的一个.这实际上是一个 著名的 Outlook 模式,在 VSTO 世界中经常被称为 InspectorWrappers - 或者在您的情况下是 DocumentWindowWrapper.

In PowerPoint 2007, custom task panes are shared across all presentation windows. If you want to have separate task panes assigned to each presentation you need to handle the corresponding events (WindowActivate, PresentationClose, etc.). You would also need to manage a list of all the task panes that you've created so you can show/hide the appropriate one. This is actually a well-known Outlook pattern frequently referred to in VSTO-world as InspectorWrappers - or in your case a DocumentWindowWrapper.

Powerpoint 2010 已更改此设置,现在每个任务窗格都与特定窗口相关联.请参阅这篇文章.

This has been changed for Powerpoint 2010 and now each taskpane is associated with a specific window. See this article.

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

Your error is that Globals.ThisAddIn.WebFormTaskPane does not necessarily correspond to the current presentations task pane - you need to lookup the proper task pane in your managed list (as mentioned above). When you create a new task pane (AfterNewPresentation), add it to your CustomTaskPane collection and provide a means of retrieving it.

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

这篇关于C# VSTO-Powerpoint-TaskPanes 在单独的窗口中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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