Office加载项VSTO任务窗格

时间:2019-05-03 05:25:29

标签: c# ms-office vsto office-addins

我正在创建PowerPoint VSTO加载项,并将其添加到活动幻灯片中。选择该内容后,我想在屏幕右侧显示一个设置任务窗格。我知道这可以通过Office Web加载项轻松完成,但是可以在VSTO加载项中完成吗?

如何使用C#在Office VSTO加载项中添加自定义任务窗格?

我正在使用Visual Studio 2019和Office 2016

1 个答案:

答案 0 :(得分:1)

您应该创建一个用户控件。在该用户控件上放置一些UI控件(在解决方案中,我放置一个文本框和一个按钮)以及事件处理。在启动时,ThisAddin将用户控件添加到自定义任务窗格。

查看我在以下链接上创建的示例解决方案 PowerPoint Snap-In

…或使用以下代码段。在ThisAddin.cs中添加两个私有,一个私有,类型为CustomTaskPane,另一个为UserControl。

    // User control
    private UserControl _usr;
   // Custom task pane
    private Microsoft.Office.Tools.CustomTaskPane _myCustomTaskPane;

创建用户控件。从项目菜单中,选择“添加用户控件”。向用户控件添加一些UI元素(例如,文本框,按钮等) 最后,在通过选择Office VSTO项目类型为您自动创建的ThisAddin_Startup事件处理程序中,添加以下行。

private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //Create an instance of the user control
            _usr =new UserControl1();
            // Connect the user control and the custom task pane 
            _myCustomTaskPane = CustomTaskPanes.Add(_usr, "My Task Pane");
            _myCustomTaskPane.Visible = true;
        }

结果如下图所示 enter image description here

有关此链接Office Development in Visual Studio的Office VSTO的更多信息