我试图用C#创建PowerPoint插件,并且每次打开或创建新演示文稿时,都会添加一个面板。我对面板的设置有疑问,可以同时打开多个演示文稿,因此我尝试制作一个这样的面板列表:
public partial class ThisAddIn
{
private UserControlA myControl1;
private UserControlA myControl2;
private UserControlA myControl3;
private UserControlA myControl4;
private UserControlA myControl5;
private List<UserControlA> myControlX;
private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane1;
private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane2;
private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane3;
private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane4;
private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane5;
private List<Microsoft.Office.Tools.CustomTaskPane> myCustomTaskPaneX;
int iNbOfInstances = 0;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
myControl1 = new UserControlA();
myControl2 = new UserControlA();
myControl3 = new UserControlA();
myControl4 = new UserControlA();
myControl5 = new UserControlA();
List<UserControlA> myControlX = new List<UserControlA> {
myControl1, myControl2, myControl3, myControl4, myControl5
};
List<Microsoft.Office.Tools.CustomTaskPane> myCustomTaskPaneX = new List<Microsoft.Office.Tools.CustomTaskPane> {
myCustomTaskPane1, myCustomTaskPane2, myCustomTaskPane3, myCustomTaskPane4, myCustomTaskPane5
};
}
当我启动PowerPoint时,我在一行上有一个错误
myCustomTaskPaneX[iNbOfInstances] = this.CustomTaskPanes.Add(myControlX[iNbOfInstances], "Addin Name");
说该引用未定义为myControlX为null
您知道我的代码有什么问题吗?PS:我尝试过调试器,并且在启动PowerPoint时,myControlX不为null,但是,一旦在PowerPoint欢迎页面中选择一个演示文稿,它就会变为null。
相关分类