ControlCollection.AddBuildingBlockGalleryContentControl Metoda

Definice

Přetížení

AddBuildingBlockGalleryContentControl(String)

Přidá nový BuildingBlockGalleryContentControl u aktuálního výběru v dokumentu.

AddBuildingBlockGalleryContentControl(ContentControl, String)

Přidá do kolekce nový BuildingBlockGalleryContentControl . Nový ovládací prvek je založen na nativním ovládacím prvku obsahu, který je již v dokumentu.

AddBuildingBlockGalleryContentControl(Range, String)

Přidá nový BuildingBlockGalleryContentControl v zadaném rozsahu v dokumentu.

AddBuildingBlockGalleryContentControl(String)

Přidá nový BuildingBlockGalleryContentControl u aktuálního výběru v dokumentu.

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

Parametry

name
String

Název nového ovládacího prvku

Návraty

Hodnota BuildingBlockGalleryContentControl přidaná do dokumentu.

Výjimky

name je null nebo má nulovou délku.

Ovládací prvek se stejným názvem je již v ControlCollectionsouboru .

Příklady

Následující příklad kódu přidá nový BuildingBlockGalleryContentControl na začátek dokumentu. Zobrazí BuildingBlockGalleryContentControl stavební bloky rovnic, které poskytuje Microsoft Office Word.

Tato verze je pro přizpůsobení na úrovni dokumentu. Pokud chcete tento kód použít, vložte ho ThisDocument do třídy v projektu a volejte metodu AddBuildingBlockControlAtSelectionThisDocument_Startup z metody .

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

Tato verze je určena pro doplněk na úrovni aplikace, který cílí na rozhraní .NET Framework 4 nebo .NET Framework 4.5. Pokud chcete tento kód použít, vložte ho ThisAddIn do třídy v projektu a volejte metodu AddBuildingBlockControlAtSelectionThisAddIn_Startup z metody .

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

Poznámky

Tato metoda slouží k přidání nového BuildingBlockGalleryContentControl do aktuálního výběru v dokumentu za běhu. Další informace najdete v tématu Přidání ovládacích prvků do dokumentů Office za běhu.

Platí pro

AddBuildingBlockGalleryContentControl(ContentControl, String)

Přidá do kolekce nový BuildingBlockGalleryContentControl . Nový ovládací prvek je založen na nativním ovládacím prvku obsahu, který je již v dokumentu.

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

Parametry

contentControl
ContentControl

To ContentControl je základ nového ovládacího prvku.

name
String

Název nového ovládacího prvku

Návraty

Hodnota BuildingBlockGalleryContentControl přidaná do dokumentu.

Výjimky

contentControl je null.-or- name je null nebo má nulovou délku.

Ovládací prvek se stejným názvem je již v ControlCollectionsouboru .

contentControlnení galerie stavebních contentControl bloků (to znamená, Type že vlastnost nemá hodnotu Microsoft.Office.Interop.Word. WdContentControlType.wdContentControlBuildingBlockGallery).

Příklady

Následující příklad kódu vytvoří novou BuildingBlockGalleryContentControl pro každou nativní galerii stavebních bloků, která je již v dokumentu.

Tato verze je pro přizpůsobení na úrovni dokumentu. Pokud chcete tento kód použít, vložte ho ThisDocument do třídy v projektu a volejte metodu CreateBuildingBlockControlsFromNativeControlsThisDocument_Startup z metody .

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

Tato verze je určena pro doplněk na úrovni aplikace, který cílí na rozhraní .NET Framework 4 nebo .NET Framework 4.5. Chcete-li tento kód použít, vložte ho ThisAddIn do třídy v projektu doplňku a zavolejte metodu CreateBuildingBlockControlsFromNativeControlsThisAddIn_Startup z metody.

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

Následující příklad kódu vytvoří novou BuildingBlockGalleryContentControl pro každou nativní galerii stavebních bloků, kterou uživatel přidá do dokumentu.

Tato verze je pro přizpůsobení na úrovni dokumentu. Pokud chcete tento kód použít, vložte ho ThisDocument do třídy v projektu. Pro jazyk C# musíte také připojit obslužnou rutinu ThisDocument_BuildingBlockContentControlAfterAdd události k ContentControlAfterAdd události ThisDocument třídy.

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

Tato verze je určena pro doplněk na úrovni aplikace, který cílí na rozhraní .NET Framework 4 nebo .NET Framework 4.5. Pokud chcete tento kód použít, vložte ho ThisAddIn do třídy v projektu. Také musíte připojit obslužnou rutinu ActiveDocument_BuildingBlockContentControlAfterAdd události k ContentControlAfterAdd události aktivního dokumentu.

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

Poznámky

Tato metoda slouží k přidání nového BuildingBlockGalleryContentControl , který je založen na nativním ovládacím prvku obsahu v dokumentu. To je užitečné, když vytvoříte BuildingBlockGalleryContentControl za běhu a chcete stejný ovládací prvek znovu vytvořit při příštím otevření dokumentu. Další informace najdete v tématu Přidání ovládacích prvků do dokumentů Office za běhu.

Platí pro

AddBuildingBlockGalleryContentControl(Range, String)

Přidá nový BuildingBlockGalleryContentControl v zadaném rozsahu v dokumentu.

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

Parametry

range
Range

A Range , který poskytuje hranice pro nový ovládací prvek.

name
String

Název nového ovládacího prvku

Návraty

Hodnota BuildingBlockGalleryContentControl přidaná do dokumentu.

Výjimky

name je null nebo má nulovou délku.

Ovládací prvek se stejným názvem je již v ControlCollectionsouboru .

Příklady

Následující příklad kódu přidá nový BuildingBlockGalleryContentControl na začátek dokumentu. Zobrazí BuildingBlockGalleryContentControl stavební bloky rovnic, které poskytuje Microsoft Office Word.

Tato verze je pro přizpůsobení na úrovni dokumentu. Pokud chcete tento kód použít, vložte ho ThisDocument do třídy v projektu a volejte metodu AddBuildingBlockControlAtRangeThisDocument_Startup z metody .

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

Tato verze je určena pro doplněk na úrovni aplikace, který cílí na rozhraní .NET Framework 4 nebo .NET Framework 4.5. Pokud chcete tento kód použít, vložte ho ThisAddIn do třídy v projektu a volejte metodu AddBuildingBlockControlAtRangeThisAddIn_Startup z metody .

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

Poznámky

Tato metoda slouží k přidání nového BuildingBlockGalleryContentControl do zadaného rozsahu v dokumentu za běhu. Další informace najdete v tématu Přidání ovládacích prvků do dokumentů Office za běhu.

Platí pro