更新:2007 年 11 月
添加一个基于文档中的本机内容控件的新 ContentControl。
命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word.v9.0(在 Microsoft.Office.Tools.Word.v9.0.dll 中)
语法
声明
Public Function AddContentControl ( _
    contentControl As ContentControl, _
    name As String _
) As ContentControl
用法
Dim instance As ControlCollection
Dim contentControl As ContentControl
Dim name As String
Dim returnValue As ContentControl
returnValue = instance.AddContentControl(contentControl, _
    name)
public ContentControl AddContentControl(
    ContentControl contentControl,
    string name
)
参数
- contentControl 
 类型:Microsoft.Office.Interop.Word.ContentControl- 作为新控件的基础的 Microsoft.Office.Interop.Word.ContentControl。 
- name 
 类型:System.String- 新控件的名称。 
返回值
类型: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 文档添加控件。
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。