Partager via


ControlCollection.AddBuildingBlockGalleryContentControl Méthode

Définition

Surcharges

AddBuildingBlockGalleryContentControl(String)

Ajoute un nouveau BuildingBlockGalleryContentControl à la sélection actuelle dans le document.

AddBuildingBlockGalleryContentControl(ContentControl, String)

Ajoute un nouveau BuildingBlockGalleryContentControl à la collection. Le nouveau contrôle est basé sur un contrôle de contenu natif qui figure déjà dans le document.

AddBuildingBlockGalleryContentControl(Range, String)

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

AddBuildingBlockGalleryContentControl(String)

Ajoute un nouveau BuildingBlockGalleryContentControl à la sélection actuelle dans le document.

public:
 Microsoft::Office::Tools::Word::BuildingBlockGalleryContentControl ^ AddBuildingBlockGalleryContentControl(System::String ^ name);
public Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl AddBuildingBlockGalleryContentControl (string name);
abstract member AddBuildingBlockGalleryContentControl : string -> Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl
Public Function AddBuildingBlockGalleryContentControl (name As String) As BuildingBlockGalleryContentControl

Paramètres

name
String

Nom du nouveau contrôle.

Retours

BuildingBlockGalleryContentControl qui a été ajouté au document.

Exceptions

name a la valeur null ou est de longueur nulle.

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

Exemples

L’exemple de code suivant ajoute un nouveau BuildingBlockGalleryContentControl au début du document. Affiche les BuildingBlockGalleryContentControl 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 ThisDocument classe de votre projet, puis appelez la AddBuildingBlockControlAtSelection méthode à partir de la ThisDocument_Startup méthode .

private Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl buildingBlockControl1;

private void AddBuildingBlockControlAtSelection()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Select();

    buildingBlockControl1 = this.Controls.AddBuildingBlockGalleryContentControl(
        "buildingBlockControl1");
    buildingBlockControl1.PlaceholderText = "Choose an equation";
    buildingBlockControl1.BuildingBlockCategory = "Built-In";
    buildingBlockControl1.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations;
}
Dim buildingBlockGalleryControl1 As Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl

Private Sub AddBuildingBlockGalleryControlAtSelection()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Select()
    buildingBlockGalleryControl1 = Me.Controls.AddBuildingBlockGalleryContentControl( _
        "buildingBlockGalleryControl1")
    With buildingBlockGalleryControl1
        .PlaceholderText = "Choose an equation"
        .BuildingBlockCategory = "Built-In"
        .BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations
    End With
End Sub

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

private Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl buildingBlockControl1;

private void AddBuildingBlockControlAtSelection()
{
    if (this.Application.ActiveDocument == null)
        return;

    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
    vstoDoc.Paragraphs[1].Range.Select();

    buildingBlockControl1 = vstoDoc.Controls.AddBuildingBlockGalleryContentControl(
        "buildingBlockControl1");
    buildingBlockControl1.PlaceholderText = "Choose an equation";
    buildingBlockControl1.BuildingBlockCategory = "Built-In";
    buildingBlockControl1.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations;
}
Dim buildingBlockGalleryControl1 As BuildingBlockGalleryContentControl

Private Sub AddBuildingBlockGalleryControlAtSelection()
    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()
    vstoDoc.Paragraphs(1).Range.Select()
    buildingBlockGalleryControl1 = vstoDoc.Controls.AddBuildingBlockGalleryContentControl( _
        "buildingBlockGalleryControl1")
    With buildingBlockGalleryControl1
        .PlaceholderText = "Choose an equation"
        .BuildingBlockCategory = "Built-In"
        .BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations
    End With
End Sub

Remarques

Utilisez cette méthode pour ajouter un nouveau BuildingBlockGalleryContentControl à la sélection actuelle dans le document au moment de l’exécution. Pour plus d'informations, consultez Adding Controls to Office Documents at Run Time.

S’applique à

AddBuildingBlockGalleryContentControl(ContentControl, String)

Ajoute un nouveau BuildingBlockGalleryContentControl à la collection. Le nouveau contrôle est basé sur un contrôle de contenu natif qui figure déjà dans le document.

public:
 Microsoft::Office::Tools::Word::BuildingBlockGalleryContentControl ^ AddBuildingBlockGalleryContentControl(Microsoft::Office::Interop::Word::ContentControl ^ contentControl, System::String ^ name);
public Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl AddBuildingBlockGalleryContentControl (Microsoft.Office.Interop.Word.ContentControl contentControl, string name);
abstract member AddBuildingBlockGalleryContentControl : Microsoft.Office.Interop.Word.ContentControl * string -> Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl
Public Function AddBuildingBlockGalleryContentControl (contentControl As ContentControl, name As String) As BuildingBlockGalleryContentControl

Paramètres

contentControl
ContentControl

ContentControl qui est la base du nouveau contrôle.

name
String

Nom du nouveau contrôle.

Retours

BuildingBlockGalleryContentControl qui a été ajouté au document.

Exceptions

contentControl est null.-ou- name est null ou a une longueur nulle.

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

contentControln’est pas une galerie de blocs de construction (autrement dit, la Type propriété de contentControl n’a pas la valeur Microsoft.Office.Interop.Word. WdContentControlType.wdContentControlBuildingBlockGallery).

Exemples

L’exemple de code suivant crée une nouvelle BuildingBlockGalleryContentControl pour chaque galerie de blocs de construction native qui se trouve déjà dans le document.

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

private System.Collections.Generic.List
   <Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl> buildingBlockControls;

private void CreateBuildingBlockControlsFromNativeControls()
{
    if (this.ContentControls.Count <= 0)
        return;

    buildingBlockControls = new System.Collections.Generic.List
        <Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl>();
    int count = 0;

    foreach (Word.ContentControl nativeControl in this.ContentControls)
    {
        if (nativeControl.Type == Word.WdContentControlType.wdContentControlBuildingBlockGallery)
        {
            count++;
            Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl tempControl =
                this.Controls.AddBuildingBlockGalleryContentControl(nativeControl,
                "VSTOBuildingBlockContentControl" + count.ToString());
            buildingBlockControls.Add(tempControl);
        }
    }
}
Private buildingBlockControls As New System.Collections.Generic.List _
        (Of Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl)

Private Sub CreateBuildingBlockGalleryControlsFromNativeControls()
    If Me.ContentControls.Count <= 0 Then
        Return
    End If

    Dim count As Integer = 0
    For Each nativeControl As Word.ContentControl In Me.ContentControls
        If nativeControl.Type = Word.WdContentControlType.wdContentControlBuildingBlockGallery Then
            count += 1
            Dim tempControl As Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl = _
                Me.Controls.AddBuildingBlockGalleryContentControl(nativeControl, _
                "VSTOBuildingBlockGalleryContentControl" + count.ToString())
            buildingBlockControls.Add(tempControl)
        End If
    Next nativeControl
End Sub

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

private System.Collections.Generic.List
   <Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl> buildingBlockControls;

private void CreateBuildingBlockControlsFromNativeControls()
{
    if (this.Application.ActiveDocument == null)
        return;

    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    if (vstoDoc.ContentControls.Count <= 0)
    {
        System.Windows.Forms.MessageBox.Show("No content controls found in document.");                    
        return;
    }

    buildingBlockControls = new System.Collections.Generic.List
        <Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl>();
    int count = 0;

    foreach (Word.ContentControl nativeControl in vstoDoc.ContentControls)
    {
        if (nativeControl.Type == Word.WdContentControlType.wdContentControlBuildingBlockGallery)
        {
            count++;
            Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl tempControl =
                vstoDoc.Controls.AddBuildingBlockGalleryContentControl(nativeControl,
                "VSTOBuildingBlockContentControl" + count.ToString());
            buildingBlockControls.Add(tempControl);
        }
    }
}
Private buildingBlockControls As New System.Collections.Generic.List _
        (Of BuildingBlockGalleryContentControl)

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

    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    If vstoDoc.ContentControls.Count <= 0 Then
        Return
    End If

    Dim count As Integer = 0
    For Each nativeControl As Word.ContentControl In vstoDoc.ContentControls
        If nativeControl.Type = Word.WdContentControlType.wdContentControlBuildingBlockGallery Then
            count += 1
            Dim tempControl As Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl = _
                vstoDoc.Controls.AddBuildingBlockGalleryContentControl(nativeControl, _
                "VSTOBuildingBlockGalleryContentControl" + count.ToString())
            buildingBlockControls.Add(tempControl)
        End If
    Next nativeControl
End Sub

L’exemple de code suivant crée une nouvelle BuildingBlockGalleryContentControl pour chaque galerie de blocs de construction native que l’utilisateur ajoute au document.

Cette version est destinée à une personnalisation au niveau du document. Pour utiliser ce code, collez-le dans la ThisDocument classe de votre projet. En C#, vous devez également attacher le ThisDocument_BuildingBlockContentControlAfterAdd gestionnaire d'événements ContentControlAfterAdd à l'événement ThisDocument .

void ThisDocument_BuildingBlockContentControlAfterAdd(Word.ContentControl NewContentControl, bool InUndoRedo)
{
    if (NewContentControl.Type == Word.WdContentControlType.wdContentControlBuildingBlockGallery)
    {
        this.Controls.AddBuildingBlockGalleryContentControl(NewContentControl,
            "BuildingBlockControl" + NewContentControl.ID);
    }
}
Private Sub ThisDocument_BuildingBlockContentControlAfterAdd(ByVal NewContentControl As Word.ContentControl, _
    ByVal InUndoRedo As Boolean) Handles Me.ContentControlAfterAdd

    If NewContentControl.Type = Word.WdContentControlType.wdContentControlBuildingBlockGallery Then
        Me.Controls.AddBuildingBlockGalleryContentControl(NewContentControl, _
            "BuildingBlockControl" + NewContentControl.ID)
    End If
End Sub

Cette version est destinée à un complément au niveau de l’application qui cible .NET Framework 4 ou .NET Framework 4.5. Pour utiliser ce code, collez-le dans la ThisAddIn classe de votre projet. En outre, vous devez joindre le ActiveDocument_BuildingBlockContentControlAfterAdd gestionnaire d’événements à l’événement ContentControlAfterAdd du document actif.

void ActiveDocument_BuildingBlockContentControlAfterAdd(
    Word.ContentControl NewContentControl, bool InUndoRedo)
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    if (NewContentControl.Type == Word.WdContentControlType.wdContentControlBuildingBlockGallery)
    {
        vstoDoc.Controls.AddBuildingBlockGalleryContentControl(NewContentControl,
            "BuildingBlockControl" + NewContentControl.ID);
    }
}
Private Sub ActiveDocument_BuildingBlockContentControlAfterAdd( _
    ByVal NewContentControl As Word.ContentControl, _
    ByVal InUndoRedo As Boolean)

    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    If NewContentControl.Type = Word.WdContentControlType. _
        wdContentControlBuildingBlockGallery Then
        vstoDoc.Controls.AddBuildingBlockGalleryContentControl(NewContentControl, _
            "BuildingBlockControl" + NewContentControl.ID)
    End If
End Sub

Remarques

Utilisez cette méthode pour ajouter un nouveau BuildingBlockGalleryContentControl qui est basé sur un contrôle de contenu natif dans le document. Cela est utile lorsque vous créez un BuildingBlockGalleryContentControl au moment de l’exécution et que vous souhaitez recréer le même contrôle lors de la prochaine ouverture du document. Pour plus d'informations, consultez Adding Controls to Office Documents at Run Time.

S’applique à

AddBuildingBlockGalleryContentControl(Range, String)

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

public:
 Microsoft::Office::Tools::Word::BuildingBlockGalleryContentControl ^ AddBuildingBlockGalleryContentControl(Microsoft::Office::Interop::Word::Range ^ range, System::String ^ name);
public Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl AddBuildingBlockGalleryContentControl (Microsoft.Office.Interop.Word.Range range, string name);
abstract member AddBuildingBlockGalleryContentControl : Microsoft.Office.Interop.Word.Range * string -> Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl
Public Function AddBuildingBlockGalleryContentControl (range As Range, name As String) As BuildingBlockGalleryContentControl

Paramètres

range
Range

Range qui indique les limites du nouveau contrôle.

name
String

Nom du nouveau contrôle.

Retours

BuildingBlockGalleryContentControl qui a été ajouté au document.

Exceptions

name a la valeur null ou est de longueur nulle.

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

Exemples

L’exemple de code suivant ajoute un nouveau BuildingBlockGalleryContentControl au début du document. Affiche les BuildingBlockGalleryContentControl 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 ThisDocument classe de votre projet, puis appelez la AddBuildingBlockControlAtRange méthode à partir de la ThisDocument_Startup méthode .

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

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

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

Remarques

Utilisez cette méthode pour ajouter un nouveau BuildingBlockGalleryContentControl au niveau d’une plage spécifiée dans le document au moment de l’exécution. Pour plus d'informations, consultez Adding Controls to Office Documents at Run Time.

S’applique à