我正在创建一个MS Word VSTO。在VSTO中,我添加了一个自定义任务窗格,在MS Word的右侧显示我的用户控件。以下是添加自定义任务窗格的代码段。
Public WithEvents _taskPane As Microsoft.Office.Tools.CustomTaskPane
Private myTaskPaneCollection As Microsoft.Office.Tools.CustomTaskPaneCollection
myTaskPaneCollection = Globals.Factory.CreateCustomTaskPaneCollection _
(Nothing, Nothing, "CustomTaskPanes", "CustomTaskPanes", Me)
_taskPane = myTaskPaneCollection.Add(dvPanel, My.Resources.dvTaskPane)
_taskPane.Control.Dock = Windows.Forms.DockStyle.Left
_taskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight
_taskPane.DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal
_taskPane.Width = 300
_taskPane.Visible = True
注意:DVPANEL是我的用户控件,它将显示有关已打开文档的元数据。
I have written this code at Application.DocumentOpen() function as I want to display task pane only when any document is opened. It work fine when i run it from MS Visual Studio. But when I opened any Document from my application. It fails. Here is the snapshot of actual error.
我搜索过很多但无法获得更多信息。这是我所评论的链接。 http://social.msdn.microsoft.com/forums/vstudio/en-US/205cdc8b-3b20-4cb8-ad30-c6177e9f8435/argument-null-reference-exception-project-addin
提前致谢。等待有利的回应。
答案 0 :(得分:1)
试试这个
Imports Microsoft.Office.Core Public Class TaskPanes Private _panes As Microsoft.Office.Tools.CustomTaskPaneCollection Public Sub AddTaskPane(ByVal cntl As System.Windows.Forms.UserControl, ByVal paneName As String) _panes = Globals.ThisAddIn.CustomTaskPanes Dim pane As Microsoft.Office.Tools.CustomTaskPane = _panes.Add(cntl, paneName) pane.Control.Dock = Windows.Forms.DockStyle.Left pane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight pane.DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal pane.Width = 300 pane.Visible = True End Sub End Class