Share via


CustomTaskPaneCollection.Add 方法 (UserControl, String, Object)

建立新的 CustomTaskPane,並將它加入至目前的 CustomTaskPaneCollection。 自訂工作窗格是以指定的 UserControl 做為基礎,具有指定的標題,並與指定的應用程式視窗相關聯。

命名空間:  Microsoft.Office.Tools
組件:  Microsoft.Office.Tools.Common (在 Microsoft.Office.Tools.Common.dll 中)

語法

'宣告
Function Add ( _
    control As UserControl, _
    title As String, _
    window As Object _
) As CustomTaskPane
CustomTaskPane Add(
    UserControl control,
    string title,
    Object window
)

參數

  • title
    型別:System.String
    出現在新自訂工作窗格標題列中的文字。
  • window
    型別:System.Object
    物件,代表要與新自訂工作窗格產生關聯的應用程式視窗。

傳回值

型別:Microsoft.Office.Tools.CustomTaskPane
代表新自訂工作窗格的 CustomTaskPane

例外狀況

例外狀況 條件
ArgumentNullException

control 或 title 是 nullNull 參照 (即 Visual Basic 中的 Nothing)。

ObjectDisposedException

已經在 CustomTaskPaneCollection 上呼叫過 Dispose() 方法。

備註

使用這個方法建立與特定應用程式視窗關聯的新 CustomTaskPane。 如果您想要建立可與 Outlook 中的多個偵測器或瀏覽器 (Explorer),或與 Word 或 InfoPath 中的多個文件一起顯示的自訂工作窗格,這個方法就很有用。 如需詳細資訊,請參閱管理多個應用程式視窗中的自訂工作窗格

window 參數的型別依應用程式而定。 下表列出 window 參數的有效型別。

應用程式

參數型別

Word

Microsoft.Office.Interop.Word.Window

Excel

Microsoft.Office.Interop.Excel.Window

PowerPoint

Microsoft.Office.Interop.PowerPoint.DocumentWindow

InfoPath

Microsoft.Office.Interop.InfoPath.WindowObject

Outlook

Microsoft.Office.Interop.Outlook.Explorer

-或-

Microsoft.Office.Interop.Outlook.Inspector

雖然 CustomTaskPaneCollectionCustomTaskPane 物件的集合,但是 Add 方法會接受 UserControl 物件,而不是 CustomTaskPane 物件。 如需詳細資訊,請參閱自訂工作窗格概觀

.NET Framework 安全性

請參閱

參考

CustomTaskPaneCollection 介面

Add 多載

Microsoft.Office.Tools 命名空間

其他資源

自訂工作窗格概觀

管理多個應用程式視窗中的自訂工作窗格