我正在创建一个PowerPoint VSTO外接程序,并将内容添加到活动幻灯片。当该内容被选中时,我想在屏幕右侧显示一个设置任务窗格。我知道用office web插件很容易做到这一点,但在VSTO插件中能做到吗?
如何使用C#在Office VSTO外接程序中添加自定义任务窗格?
即时通信工具使用Visual Studio 2019和Office 2016
发布于 2019-05-03 15:20:38
您应该创建一个用户控件。在该用户控件上放置一些UI控件(在解决方案中,我放置了一个文本框和一个按钮)以及事件处理。启动时,ThisAddin会将用户控件添加到自定义任务窗格中。
查看我在以下链接PowerPoint Snap-In上创建的示例解决方案
…或者使用以下代码片段。在ThisAddin.cs中添加两个privates,一个是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;
}结果如下图所示

有关Office VSTO的更多信息,请访问此链接Office Development in Visual Studio
https://stackoverflow.com/questions/55963751
复制相似问题