Share via


ControlCollection.AddBuildingBlockGalleryContentControl, méthode (Range, String)

Ajoute un nouveau BuildingBlockGalleryContentControl dans la plage spécifiée dans le document.

Espace de noms :  Microsoft.Office.Tools.Word
Assembly :  Microsoft.Office.Tools.Word (dans Microsoft.Office.Tools.Word.dll)

Syntaxe

'Déclaration
Function AddBuildingBlockGalleryContentControl ( _
    range As Range, _
    name As String _
) As BuildingBlockGalleryContentControl
BuildingBlockGalleryContentControl AddBuildingBlockGalleryContentControl(
    Range range,
    string name
)

Paramètres

Valeur de retour

Type : Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl
BuildingBlockGalleryContentControl ajouté au document.

Exceptions

Exception Condition
ArgumentNullException

name est nullune référence null (Nothing en Visual Basic) ou une longueur nulle.

ControlNameAlreadyExistsException

Un contrôle du même nom figure déjà dans ControlCollection.

Notes

Utilisez cette méthode pour ajouter un nouveau BuildingBlockGalleryContentControl dans la plage spécifiée dans le document au moment de l'exécution. Pour plus d'informations, consultez Ajout de contrôles à des documents Office au moment de l'exécution.

Exemples

L'exemple de code suivant ajoute un nouveau BuildingBlockGalleryContentControl au début du document. BuildingBlockGalleryContentControl affiche des blocs de construction d'équation fournis par Microsoft Office Word.

Cette version est destinée à une personnalisation au niveau du document. Pour utiliser ce code, collez-le dans la classe ThisDocument de votre projet, puis appelez la méthode AddBuildingBlockControlAtRange à partir de la méthode ThisDocument_Startup.

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;
}

Cette version concerne un complément de niveau application qui cible le .NET Framework 4 ou le .NET Framework 4.5. Pour utiliser ce code, collez-le dans la classe ThisAddIn de votre projet, puis appelez la méthode AddBuildingBlockControlAtRange à partir de la méthode ThisAddIn_Startup.

Dim buildingBlockGalleryControl2 As BuildingBlockGalleryContentControl

Private Sub AddBuildingBlockGalleryControlAtRange()
    If Me.Application.ActiveDocument Is Nothing Then
        Return
    End If

    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    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 = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    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;
}

Sécurité .NET Framework

Voir aussi

Référence

ControlCollection Interface

AddBuildingBlockGalleryContentControl, surcharge

Microsoft.Office.Tools.Word, espace de noms

Autres ressources

Ajout de contrôles à des documents Office au moment de l'exécution

Comment : ajouter des contrôles de contenu à des documents Word