猿问

为什么 CustomTaskPane 抛出空异常

我正在创建 VSTO插件并且我已经尝试将 winform 插件添加到 Word 中的自定义任务窗格, 但它抛出了 NullReferenceException。


        CustomTaskPaneCollection CustomTaskPanes;

        CustomTaskPane ct;

        Pdfcontrol pdf = new Pdfcontrol();

        ct = Globals.ThisDocument.CustomTaskPanes.Add(pdf, "Pdf");


qq_花开花谢_0
浏览 112回答 1
1回答

临摹微笑

ThisDocument没有CustomTaskPanes属性,这甚至不应该编译。您得到的答案是针对应用程序级加载项,而您有一个文档级加载项。在你的情况下,你想这样做:Pdfcontrol pdf = new Pdfcontrol();Globals.ThisDocument.ActionsPane.Controls.Add(pdf)
随时随地看视频慕课网APP
我要回答