更新: 2008 年 7 月
在文档中的指定范围内添加一个新的 BuildingBlockGalleryContentControl。
命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word.v9.0(在 Microsoft.Office.Tools.Word.v9.0.dll 中)
语法
声明
Public Function AddBuildingBlockGalleryContentControl ( _
    range As Range, _
    name As String _
) As BuildingBlockGalleryContentControl
用法
Dim instance As ControlCollection
Dim range As Range
Dim name As String
Dim returnValue As BuildingBlockGalleryContentControl
returnValue = instance.AddBuildingBlockGalleryContentControl(range, _
    name)
public BuildingBlockGalleryContentControl AddBuildingBlockGalleryContentControl(
    Range range,
    string name
)
参数
- range 
 类型:Microsoft.Office.Interop.Word.Range- 提供新控件的界限的 Range。 
- name 
 类型:System.String- 新控件的名称。 
返回值
类型:Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl
添加到文档的 BuildingBlockGalleryContentControl。
异常
| 异常 | 条件 | 
|---|---|
| ArgumentNullException | name 为 nullnull 引用(在 Visual Basic 中为 Nothing) 或长度为零。 | 
| ControlNameAlreadyExistsException | ControlCollection 中已存在一个同名控件。 | 
备注
使用此方法,可在运行时在文档中的指定范围内添加一个新的 BuildingBlockGalleryContentControl。有关更多信息,请参见在运行时向 Office 文档添加控件。
示例
下面的代码示例会在文档开头添加一个新的 BuildingBlockGalleryContentControl。BuildingBlockGalleryContentControl 显示由 Microsoft Office Word 提供的方程式生成块。
此版本针对的是文档级自定义项。若要使用此代码,请将其粘贴到项目内的 ThisDocument 类中,然后从 ThisDocument_Startup 方法中调用 AddBuildingBlockControlAtRange 方法。
Dim buildingBlockGalleryControl2 As Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl
Private Sub AddBuildingBlockGalleryControlAtRange()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    buildingBlockGalleryControl2 = Me.Controls.AddBuildingBlockGalleryContentControl( _
        Me.Paragraphs(1).Range, "buildingBlockGalleryControl2")
    With buildingBlockGalleryControl2
        .PlaceholderText = "Choose an equation"
        .BuildingBlockCategory = "Built-In"
        .BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations
    End With
End Sub
private Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl buildingBlockControl2;
private void AddBuildingBlockControlAtRange()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    buildingBlockControl2 = this.Controls.AddBuildingBlockGalleryContentControl(
       this.Paragraphs[1].Range, "buildingBlockControl2");
    buildingBlockControl2.PlaceholderText = "Choose an equation";
    buildingBlockControl2.BuildingBlockCategory = "Built-In";
    buildingBlockControl2.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations;
}
此版本针对的是应用程序级外接程序。若要使用此代码,请将其粘贴到项目内的 ThisAddIn 类中,然后从 ThisAddIn_Startup 方法中调用 AddBuildingBlockControlAtRange 方法。
Dim buildingBlockGalleryControl2 As BuildingBlockGalleryContentControl
Private Sub AddBuildingBlockGalleryControlAtRange()
    If Me.Application.ActiveDocument Is Nothing Then
        Return
    End If
    Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
    vstoDoc.Paragraphs(1).Range.InsertParagraphBefore()
    buildingBlockGalleryControl2 = vstoDoc.Controls.AddBuildingBlockGalleryContentControl( _
        vstoDoc.Paragraphs(1).Range, "buildingBlockGalleryControl2")
    With buildingBlockGalleryControl2
        .PlaceholderText = "Choose an equation"
        .BuildingBlockCategory = "Built-In"
        .BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations
    End With
End Sub
private Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl buildingBlockControl2;
private void AddBuildingBlockControlAtRange()
{
    if (this.Application.ActiveDocument == null)
        return;
    Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
    vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
    buildingBlockControl2 = vstoDoc.Controls.AddBuildingBlockGalleryContentControl(
       vstoDoc.Paragraphs[1].Range, "buildingBlockControl2");
    buildingBlockControl2.PlaceholderText = "Choose an equation";
    buildingBlockControl2.BuildingBlockCategory = "Built-In";
    buildingBlockControl2.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations;
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
另请参见
参考
AddBuildingBlockGalleryContentControl 重载
Microsoft.Office.Tools.Word 命名空间
其他资源
修订记录
| 日期 | 修订记录 | 原因 | 
|---|---|---|
| 2008 年 7 月 | 添加了一个针对应用程序级外接程序的代码示例版本。 | SP1 功能更改。 |