次の方法で共有


ControlCollection.AddBuildingBlockGalleryContentControl メソッド

定義

オーバーロード

AddBuildingBlockGalleryContentControl(String)

ドキュメントの現在の選択範囲に新しい BuildingBlockGalleryContentControl を追加します。

AddBuildingBlockGalleryContentControl(ContentControl, String)

新しい BuildingBlockGalleryContentControl をコレクションに追加します。 新しいコントロールは、ドキュメントに既に存在するネイティブ コンテンツ コントロールに基づいています。

AddBuildingBlockGalleryContentControl(Range, String)

ドキュメント内の指定した範囲に新しい BuildingBlockGalleryContentControl を追加します。

AddBuildingBlockGalleryContentControl(String)

ドキュメントの現在の選択範囲に新しい BuildingBlockGalleryContentControl を追加します。

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

パラメーター

name
String

新しいコントロールの名前。

戻り値

ドキュメントに追加された BuildingBlockGalleryContentControl

例外

name は、null であるか、または長さがゼロです。

ControlCollection に既に同じ名前のコントロールがあります。

次のコード例では、ドキュメントの先頭に新しい BuildingBlockGalleryContentControl を追加します。 にはBuildingBlockGalleryContentControl、Microsoft Office Wordによって提供される数式の構成要素が表示されます。

このバージョンは、ドキュメント レベルのカスタマイズ用です。 このコードを使用するには、プロジェクトの ThisDocument クラスに貼り付け、 メソッドから メソッドをAddBuildingBlockControlAtSelectionThisDocument_Startup呼び出します。

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

このバージョンは、.NET Framework 4 または.NET Framework 4.5 を対象とするアプリケーション レベルのアドイン用です。 このコードを使用するには、プロジェクトの ThisAddIn クラスに貼り付け、 メソッドから メソッドをAddBuildingBlockControlAtSelectionThisAddIn_Startup呼び出します。

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

注釈

実行時にドキュメント内の現在の選択範囲に新しい BuildingBlockGalleryContentControl を追加するには、このメソッドを使用します。 詳細については、「 Adding Controls to Office Documents at Run Time」を参照してください。

適用対象

AddBuildingBlockGalleryContentControl(ContentControl, String)

新しい BuildingBlockGalleryContentControl をコレクションに追加します。 新しいコントロールは、ドキュメントに既に存在するネイティブ コンテンツ コントロールに基づいています。

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

パラメーター

contentControl
ContentControl

新しいコントロールのベースとなる ContentControl

name
String

新しいコントロールの名前。

戻り値

ドキュメントに追加された BuildingBlockGalleryContentControl

例外

contentControlnull.-or- name であるか、 null 長さが 0 です。

ControlCollection に既に同じ名前のコントロールがあります。

contentControlは文書パーツ ギャラリーではありません (つまり、 TypecontentControl プロパティに Microsoft.Office.Interop.Word の値がありません。WdContentControlType.wdContentControlBuildingBlockGallery)。

次のコード例では、ドキュメントに既に存在するすべてのネイティブ文書パーツ ギャラリーに対して新しい BuildingBlockGalleryContentControl を作成します。

このバージョンは、ドキュメント レベルのカスタマイズ用です。 このコードを使用するには、プロジェクトの ThisDocument クラスに貼り付け、 メソッドから メソッドをCreateBuildingBlockControlsFromNativeControlsThisDocument_Startup呼び出します。

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

このバージョンは、.NET Framework 4 または.NET Framework 4.5 を対象とするアプリケーション レベルのアドイン用です。 このコードを使用するには、アドイン プロジェクトの ThisAddIn クラスに貼り付け、 メソッドから メソッドをCreateBuildingBlockControlsFromNativeControlsThisAddIn_Startup呼び出します。

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

次のコード例では、ユーザーがドキュメントに追加するすべてのネイティブ文書パーツ ギャラリーに対して新しい BuildingBlockGalleryContentControl を作成します。

このバージョンは、ドキュメント レベルのカスタマイズ用です。 このコードを使用するには、プロジェクトの ThisDocument クラスに貼り付けます。 C# の場合は、 クラスの イベントにThisDocument_BuildingBlockContentControlAfterAddイベント ThisDocument ハンドラーをContentControlAfterAddアタッチする必要もあります。

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

このバージョンは、.NET Framework 4 または.NET Framework 4.5 を対象とするアプリケーション レベルのアドイン用です。 このコードを使用するには、プロジェクトの ThisAddIn クラスに貼り付けます。 また、作業中の文書の ActiveDocument_BuildingBlockContentControlAfterAdd イベントにイベント ハンドラーを ContentControlAfterAdd アタッチする必要があります。

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

注釈

ドキュメント内のネイティブ コンテンツ コントロールに基づく新しい BuildingBlockGalleryContentControl を追加するには、このメソッドを使用します。 これは、実行時に を BuildingBlockGalleryContentControl 作成し、次回ドキュメントを開いたときに同じコントロールを再作成する場合に便利です。 詳細については、「 Adding Controls to Office Documents at Run Time」を参照してください。

適用対象

AddBuildingBlockGalleryContentControl(Range, String)

ドキュメント内の指定した範囲に新しい BuildingBlockGalleryContentControl を追加します。

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

パラメーター

range
Range

新しいコントロールの境界を指定する Range

name
String

新しいコントロールの名前。

戻り値

ドキュメントに追加された BuildingBlockGalleryContentControl

例外

name は、null であるか、または長さがゼロです。

ControlCollection に既に同じ名前のコントロールがあります。

次のコード例では、ドキュメントの先頭に新しい BuildingBlockGalleryContentControl を追加します。 にはBuildingBlockGalleryContentControl、Microsoft Office Wordによって提供される数式の構成要素が表示されます。

このバージョンは、ドキュメント レベルのカスタマイズ用です。 このコードを使用するには、プロジェクトの ThisDocument クラスに貼り付け、 メソッドから メソッドをAddBuildingBlockControlAtRangeThisDocument_Startup呼び出します。

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

このバージョンは、.NET Framework 4 または.NET Framework 4.5 を対象とするアプリケーション レベルのアドイン用です。 このコードを使用するには、プロジェクトの ThisAddIn クラスに貼り付け、 メソッドから メソッドをAddBuildingBlockControlAtRangeThisAddIn_Startup呼び出します。

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

注釈

実行時にドキュメント内の指定した範囲に新しい BuildingBlockGalleryContentControl を追加するには、このメソッドを使用します。 詳細については、「 Adding Controls to Office Documents at Run Time」を参照してください。

適用対象