ControlCollection.AddContentControl 方法 (ContentControl, String)

添加一个基于文档中的本机内容控件的新 ContentControl

命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word(在 Microsoft.Office.Tools.Word.dll 中)

语法

声明
Function AddContentControl ( _
    contentControl As ContentControl, _
    name As String _
) As ContentControl
ContentControl AddContentControl(
    ContentControl contentControl,
    string name
)

参数

返回值

类型:Microsoft.Office.Tools.Word.ContentControl
添加到文档的 ContentControl

异常

异常 条件
ArgumentNullException

contentControl 为 nullnull 引用(在 Visual Basic 中为 Nothing)。

- 或 -

name 为 nullnull 引用(在 Visual Basic 中为 Nothing) 或长度为零。

ControlNameAlreadyExistsException

ControlCollection 中已存在一个同名控件。

ArgumentException

contentControl 不是生成块库(即 contentControl 的 Microsoft.Office.Interop.Word.ContentControl.Type 属性不具有 Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlRichText 值)。

备注

使用此方法,可以在运行时添加基于文档中的本机内容控件的新 ContentControl。如果在运行时创建 ContentControl,并且希望在下次打开文档时重新创建相同的控件,这非常有用。有关更多信息,请参见在运行时向 Office 文档添加控件

.NET Framework 安全性

请参见

参考

ControlCollection 接口

AddContentControl 重载

Microsoft.Office.Tools.Word 命名空间