次の方法で共有


ControlCollection.AddComboBoxContentControl メソッド (Range, String)

新しい ComboBoxContentControl を指定された範囲で文書に追加します。

名前空間:  Microsoft.Office.Tools.Word
アセンブリ:  Microsoft.Office.Tools.Word (Microsoft.Office.Tools.Word.dll 内)

構文

'宣言
Function AddComboBoxContentControl ( _
    range As Range, _
    name As String _
) As ComboBoxContentControl
ComboBoxContentControl AddComboBoxContentControl(
    Range range,
    string name
)

パラメーター

戻り値

型: Microsoft.Office.Tools.Word.ComboBoxContentControl
文書に追加された ComboBoxContentControl

例外

例外 条件
ArgumentNullException

name が nullnull 参照 (Visual Basic では Nothing) であるか、または長さが 0 である場合。

ControlNameAlreadyExistsException

同じ名前のコントロールが既に ControlCollection に存在する場合。

解説

このメソッドを使用して、実行時における文書の指定された範囲で新しい ComboBoxContentControl を追加します。 詳細については、「実行時の Office ドキュメントへのコントロールの追加」を参照してください。

次のコード例は、文書の先頭に新しい ComboBoxContentControl を追加します。 この例では、コントロールでユーザーが選択できる項目の一覧に、いくつかの色名を追加することも行います。

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

Dim comboBoxControl2 As Microsoft.Office.Tools.Word.ComboBoxContentControl

Private Sub AddComboBoxControlAtRange()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    comboBoxControl2 = Me.Controls.AddComboBoxContentControl(Me.Paragraphs(1).Range, "comboBoxControl2")
    With comboBoxControl2
        .DropDownListEntries.Add("Red", "Red", 0)
        .DropDownListEntries.Add("Green", "Green", 1)
        .DropDownListEntries.Add("Blue", "Blue", 2)
        .PlaceholderText = "Choose a color, or enter your own"
    End With
End Sub
private Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl2;

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

    comboBoxControl2 = this.Controls.AddComboBoxContentControl(this.Paragraphs[1].Range,
        "comboBoxControl2");
    comboBoxControl2.DropDownListEntries.Add("Red", "Red", 0);
    comboBoxControl2.DropDownListEntries.Add("Green", "Green", 1);
    comboBoxControl2.DropDownListEntries.Add("Blue", "Blue", 2);
    comboBoxControl2.PlaceholderText = "Choose a color, or enter your own";
}

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

Dim comboBoxControl2 As Microsoft.Office.Tools.Word.ComboBoxContentControl

Private Sub AddComboBoxControlAtRange()
    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()
    comboBoxControl2 = vstoDoc.Controls.AddComboBoxContentControl( _
        vstoDoc.Paragraphs(1).Range, "comboBoxControl2")
    With comboBoxControl2
        .DropDownListEntries.Add("Red", "Red", 0)
        .DropDownListEntries.Add("Green", "Green", 1)
        .DropDownListEntries.Add("Blue", "Blue", 2)
        .PlaceholderText = "Choose a color, or enter your own"
    End With
End Sub
private Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl2;

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

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

    comboBoxControl2 = vstoDoc.Controls.AddComboBoxContentControl(
        vstoDoc.Paragraphs[1].Range,
        "comboBoxControl2");
    comboBoxControl2.DropDownListEntries.Add("Red", "Red", 0);
    comboBoxControl2.DropDownListEntries.Add("Green", "Green", 1);
    comboBoxControl2.DropDownListEntries.Add("Blue", "Blue", 2);
    comboBoxControl2.PlaceholderText = "Choose a color, or enter your own";            
}

.NET Framework セキュリティ

  • 直前の呼び出し元に対する完全な信頼。 このメンバーは、部分的に信頼されているコードから使用することはできません。 詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

参照

ControlCollection インターフェイス

AddComboBoxContentControl オーバーロード

Microsoft.Office.Tools.Word 名前空間

その他の技術情報

実行時の Office ドキュメントへのコントロールの追加

ホスト コントロールのヘルパー メソッド

方法 : Word 文書にコンテンツ コントロールを追加する