Compartir a través de


ControlCollection.AddBuildingBlockGalleryContentControl Método

Definición

Sobrecargas

AddBuildingBlockGalleryContentControl(String)

Agrega un nuevo objeto BuildingBlockGalleryContentControl en la selección actual del documento.

AddBuildingBlockGalleryContentControl(ContentControl, String)

Agrega un nuevo objeto BuildingBlockGalleryContentControl a la colección. El nuevo control se basa en un control de contenido nativo que ya se encuentra en el documento.

AddBuildingBlockGalleryContentControl(Range, String)

Agrega un nuevo objeto BuildingBlockGalleryContentControl en el intervalo especificado en el documento.

AddBuildingBlockGalleryContentControl(String)

Agrega un nuevo objeto BuildingBlockGalleryContentControl en la selección actual del documento.

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

Parámetros

name
String

El nombre del nuevo control.

Devoluciones

El objeto BuildingBlockGalleryContentControl que se agregó al documento.

Excepciones

name es null o tiene una longitud cero.

Un control con el mismo nombre ya se encuentra en el objeto ControlCollection.

Ejemplos

En el ejemplo de código siguiente se agrega un nuevo BuildingBlockGalleryContentControl al principio del documento. BuildingBlockGalleryContentControl Muestra los bloques de creación de ecuaciones proporcionados por Microsoft Office Word.

Esta versión es para una personalización de nivel de documento. Para usar este código, péguelo en la ThisDocument clase del proyecto y llame al AddBuildingBlockControlAtSelection método desde el ThisDocument_Startup método .

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

Esta versión es para un complemento de nivel de aplicación que tiene como destino .NET Framework 4 o .NET Framework 4.5. Para usar este código, péguelo en la ThisAddIn clase del proyecto y llame al AddBuildingBlockControlAtSelection método desde el ThisAddIn_Startup método .

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

Comentarios

Use este método para agregar un nuevo BuildingBlockGalleryContentControl en la selección actual del documento en tiempo de ejecución. Para obtener más información, consulta Adding Controls to Office Documents at Run Time.

Se aplica a

AddBuildingBlockGalleryContentControl(ContentControl, String)

Agrega un nuevo objeto BuildingBlockGalleryContentControl a la colección. El nuevo control se basa en un control de contenido nativo que ya se encuentra en el documento.

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

Parámetros

contentControl
ContentControl

El objeto ContentControl que es la base del nuevo control.

name
String

El nombre del nuevo control.

Devoluciones

El objeto BuildingBlockGalleryContentControl que se agregó al documento.

Excepciones

contentControl es null.-o- name es null o tiene una longitud cero.

Un control con el mismo nombre ya se encuentra en el objeto ControlCollection.

contentControlno es una galería de bloques de creación (es decir, la Type propiedad de contentControl no tiene el valor Microsoft.Office.Interop.Word. WdContentControlType.wdContentControlBuildingBlockGallery).

Ejemplos

En el ejemplo de código siguiente se crea un nuevo BuildingBlockGalleryContentControl para cada galería de bloques de creación nativa que ya está en el documento.

Esta versión es para una personalización de nivel de documento. Para usar este código, péguelo en la ThisDocument clase del proyecto y llame al CreateBuildingBlockControlsFromNativeControls método desde el ThisDocument_Startup método .

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

Esta versión es para un complemento de nivel de aplicación que tiene como destino .NET Framework 4 o .NET Framework 4.5. Para usar este código, péguelo en la ThisAddIn clase del proyecto de complemento y llame al CreateBuildingBlockControlsFromNativeControls método desde el ThisAddIn_Startup método .

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

En el ejemplo de código siguiente se crea un nuevo BuildingBlockGalleryContentControl para cada galería de bloques de creación nativa que el usuario agrega al documento.

Esta versión es para una personalización de nivel de documento. Para usar este código, péguelo en la ThisDocument clase del proyecto. Para C#, también debe adjuntar el ThisDocument_BuildingBlockContentControlAfterAdd controlador de eventos al ContentControlAfterAdd evento de la ThisDocument clase .

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

Esta versión es para un complemento de nivel de aplicación que tiene como destino .NET Framework 4 o .NET Framework 4.5. Para usar este código, péguelo en la ThisAddIn clase del proyecto. Además, debe adjuntar el ActiveDocument_BuildingBlockContentControlAfterAdd controlador de eventos al ContentControlAfterAdd evento del documento activo.

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

Comentarios

Utilice este método para agregar un nuevo BuildingBlockGalleryContentControl elemento basado en un control de contenido nativo en el documento. Esto resulta útil al crear un objeto BuildingBlockGalleryContentControl en tiempo de ejecución y desea volver a crear el mismo control la próxima vez que se abra el documento. Para obtener más información, consulta Adding Controls to Office Documents at Run Time.

Se aplica a

AddBuildingBlockGalleryContentControl(Range, String)

Agrega un nuevo objeto BuildingBlockGalleryContentControl en el intervalo especificado en el documento.

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

Parámetros

range
Range

Un objeto Range que proporciona los límites del nuevo control.

name
String

El nombre del nuevo control.

Devoluciones

El objeto BuildingBlockGalleryContentControl que se agregó al documento.

Excepciones

name es null o tiene una longitud cero.

Un control con el mismo nombre ya se encuentra en el objeto ControlCollection.

Ejemplos

En el ejemplo de código siguiente se agrega un nuevo BuildingBlockGalleryContentControl al principio del documento. BuildingBlockGalleryContentControl Muestra los bloques de creación de ecuaciones proporcionados por Microsoft Office Word.

Esta versión es para una personalización de nivel de documento. Para usar este código, péguelo en la ThisDocument clase del proyecto y llame al AddBuildingBlockControlAtRange método desde el ThisDocument_Startup método .

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

Esta versión es para un complemento de nivel de aplicación que tiene como destino .NET Framework 4 o .NET Framework 4.5. Para usar este código, péguelo en la ThisAddIn clase del proyecto y llame al AddBuildingBlockControlAtRange método desde el ThisAddIn_Startup método .

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

Comentarios

Use este método para agregar un nuevo BuildingBlockGalleryContentControl en un intervalo especificado en el documento en tiempo de ejecución. Para obtener más información, consulta Adding Controls to Office Documents at Run Time.

Se aplica a