ControlCollection.AddComboBoxContentControl メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
オーバーロード
AddComboBoxContentControl(String) |
ドキュメントの現在の選択範囲に新しい ComboBoxContentControl を追加します。 |
AddComboBoxContentControl(ContentControl, String) |
新しい ComboBoxContentControl をコレクションに追加します。 新しいコントロールは、ドキュメントに既に存在するネイティブ コンテンツ コントロールに基づいています。 |
AddComboBoxContentControl(Range, String) |
ドキュメント内の指定した範囲に新しい ComboBoxContentControl を追加します。 |
AddComboBoxContentControl(String)
ドキュメントの現在の選択範囲に新しい ComboBoxContentControl を追加します。
public:
Microsoft::Office::Tools::Word::ComboBoxContentControl ^ AddComboBoxContentControl(System::String ^ name);
public Microsoft.Office.Tools.Word.ComboBoxContentControl AddComboBoxContentControl (string name);
abstract member AddComboBoxContentControl : string -> Microsoft.Office.Tools.Word.ComboBoxContentControl
Public Function AddComboBoxContentControl (name As String) As ComboBoxContentControl
パラメーター
- name
- String
新しいコントロールの名前。
戻り値
ドキュメントに追加された ComboBoxContentControl。
例外
name
は、null
であるか、または長さがゼロです。
ControlCollection に既に同じ名前のコントロールがあります。
例
次のコード例では、ドキュメントの先頭に新しい ComboBoxContentControl を追加します。 この例では、ユーザーがコントロールで選択できる項目の一覧に、複数の色の名前も追加します。
このバージョンは、ドキュメント レベルのカスタマイズ用です。 このコードを使用するには、プロジェクトの ThisDocument
クラスに貼り付け、 メソッドから メソッドをAddComboBoxControlAtSelection
ThisDocument_Startup
呼び出します。
private Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl1;
private void AddComboBoxControlAtSelection()
{
this.Paragraphs[1].Range.InsertParagraphBefore();
this.Paragraphs[1].Range.Select();
comboBoxControl1 = this.Controls.AddComboBoxContentControl("comboBoxControl1");
comboBoxControl1.DropDownListEntries.Add("Red", "Red", 0);
comboBoxControl1.DropDownListEntries.Add("Green", "Green", 1);
comboBoxControl1.DropDownListEntries.Add("Blue", "Blue", 2);
comboBoxControl1.PlaceholderText = "Choose a color, or enter your own";
}
Dim comboBoxControl1 As Microsoft.Office.Tools.Word.ComboBoxContentControl
Private Sub AddComboBoxControlAtSelection()
Me.Paragraphs(1).Range.InsertParagraphBefore()
Me.Paragraphs(1).Range.Select()
comboBoxControl1 = Me.Controls.AddComboBoxContentControl("comboBoxControl1")
With comboBoxControl1
.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
このバージョンは、.NET Framework 4 または.NET Framework 4.5 を対象とするアプリケーション レベルのアドイン用です。 このコードを使用するには、プロジェクトの ThisAddIn
クラスに貼り付け、 メソッドから メソッドをAddComboBoxControlAtSelection
ThisAddIn_Startup
呼び出します。
private Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl1;
private void AddComboBoxControlAtSelection()
{
if (this.Application.ActiveDocument == null)
return;
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
vstoDoc.Paragraphs[1].Range.Select();
comboBoxControl1 = vstoDoc.Controls.AddComboBoxContentControl(
"comboBoxControl1");
comboBoxControl1.DropDownListEntries.Add("Red", "Red", 0);
comboBoxControl1.DropDownListEntries.Add("Green", "Green", 1);
comboBoxControl1.DropDownListEntries.Add("Blue", "Blue", 2);
comboBoxControl1.PlaceholderText = "Choose a color, or enter your own";
}
Dim comboBoxControl1 As Microsoft.Office.Tools.Word.ComboBoxContentControl
Private Sub AddComboBoxControlAtSelection()
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()
comboBoxControl1 = vstoDoc.Controls.AddComboBoxContentControl("comboBoxControl1")
With comboBoxControl1
.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
注釈
実行時にドキュメント内の現在の選択範囲に新しい ComboBoxContentControl を追加するには、このメソッドを使用します。 詳細については、「 Adding Controls to Office Documents at Run Time」を参照してください。
適用対象
AddComboBoxContentControl(ContentControl, String)
新しい ComboBoxContentControl をコレクションに追加します。 新しいコントロールは、ドキュメントに既に存在するネイティブ コンテンツ コントロールに基づいています。
public:
Microsoft::Office::Tools::Word::ComboBoxContentControl ^ AddComboBoxContentControl(Microsoft::Office::Interop::Word::ContentControl ^ contentControl, System::String ^ name);
public Microsoft.Office.Tools.Word.ComboBoxContentControl AddComboBoxContentControl (Microsoft.Office.Interop.Word.ContentControl contentControl, string name);
abstract member AddComboBoxContentControl : Microsoft.Office.Interop.Word.ContentControl * string -> Microsoft.Office.Tools.Word.ComboBoxContentControl
Public Function AddComboBoxContentControl (contentControl As ContentControl, name As String) As ComboBoxContentControl
パラメーター
- contentControl
- ContentControl
新しいコントロールのベースとなる ContentControl。
- name
- String
新しいコントロールの名前。
戻り値
ドキュメントに追加された ComboBoxContentControl。
例外
contentControl
が null
.-or- name
であるか、 null
長さが 0 です。
ControlCollection に既に同じ名前のコントロールがあります。
contentControl
は文書パーツ ギャラリーではありません (つまり、 Type の contentControl
プロパティに Microsoft.Office.Interop.Word の値がありません。WdContentControlType.wdContentControlComboBox)。
例
次のコード例では、ドキュメントに既に存在するすべてのネイティブ コンボ ボックスに対して新しい ComboBoxContentControl を作成します。
このバージョンは、ドキュメント レベルのカスタマイズ用です。 このコードを使用するには、プロジェクトの ThisDocument
クラスに貼り付け、 メソッドから メソッドをCreateComboBoxControlsFromNativeControls
ThisDocument_Startup
呼び出します。
private System.Collections.Generic.List
<Microsoft.Office.Tools.Word.ComboBoxContentControl> comboBoxControls;
private void CreateComboBoxControlsFromNativeControls()
{
if (this.ContentControls.Count <= 0)
return;
comboBoxControls = new System.Collections.Generic.List
<Microsoft.Office.Tools.Word.ComboBoxContentControl>();
int count = 0;
foreach (Word.ContentControl nativeControl in this.ContentControls)
{
if (nativeControl.Type == Word.WdContentControlType.wdContentControlComboBox)
{
count++;
Microsoft.Office.Tools.Word.ComboBoxContentControl tempControl =
this.Controls.AddComboBoxContentControl(nativeControl,
"VSTOComboBoxContentControl" + count.ToString());
comboBoxControls.Add(tempControl);
}
}
}
Private comboBoxControls As New System.Collections.Generic.List _
(Of Microsoft.Office.Tools.Word.ComboBoxContentControl)
Private Sub CreateComboBoxControlsFromNativeControls()
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.wdContentControlComboBox Then
count += 1
Dim tempControl As Microsoft.Office.Tools.Word.ComboBoxContentControl = _
Me.Controls.AddComboBoxContentControl(nativeControl, _
"VSTOComboBoxContentControl" + count.ToString())
comboBoxControls.Add(tempControl)
End If
Next nativeControl
End Sub
このバージョンは、.NET Framework 4 または.NET Framework 4.5 を対象とするアプリケーション レベルのアドイン用です。 このコードを使用するには、プロジェクトの ThisAddIn
クラスに貼り付け、 メソッドから メソッドをCreateComboBoxControlsFromNativeControls
ThisAddIn_Startup
呼び出します。
private System.Collections.Generic.List
<Microsoft.Office.Tools.Word.ComboBoxContentControl> comboBoxControls;
private void CreateComboBoxControlsFromNativeControls()
{
if (this.Application.ActiveDocument == null)
return;
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
if (vstoDoc.ContentControls.Count <= 0)
return;
comboBoxControls = new System.Collections.Generic.List
<Microsoft.Office.Tools.Word.ComboBoxContentControl>();
int count = 0;
foreach (Word.ContentControl nativeControl in vstoDoc.ContentControls)
{
if (nativeControl.Type == Word.WdContentControlType.wdContentControlComboBox)
{
count++;
Microsoft.Office.Tools.Word.ComboBoxContentControl tempControl =
vstoDoc.Controls.AddComboBoxContentControl(nativeControl,
"VSTOComboBoxContentControl" + count.ToString());
comboBoxControls.Add(tempControl);
}
}
}
Private comboBoxControls As New System.Collections.Generic.List _
(Of Microsoft.Office.Tools.Word.ComboBoxContentControl)
Private Sub CreateComboBoxControlsFromNativeControls()
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.wdContentControlComboBox Then
count += 1
Dim tempControl As Microsoft.Office.Tools.Word.ComboBoxContentControl = _
vstoDoc.Controls.AddComboBoxContentControl(nativeControl, _
"VSTOComboBoxContentControl" + count.ToString())
comboBoxControls.Add(tempControl)
End If
Next nativeControl
End Sub
次のコード例では、ユーザーがドキュメントに追加するすべてのネイティブ コンボ ボックスに対して新しい ComboBoxContentControl を作成します。
このバージョンは、ドキュメント レベルのカスタマイズ用です。 このコードを使用するには、プロジェクトの ThisDocument
クラスに貼り付けます。 C# の場合は、 クラスの イベントにThisDocument_ComboBoxContentControlAfterAdd
イベント ThisDocument
ハンドラーをContentControlAfterAddアタッチする必要もあります。
void ThisDocument_ComboBoxContentControlAfterAdd(Word.ContentControl NewContentControl, bool InUndoRedo)
{
if (NewContentControl.Type == Word.WdContentControlType.wdContentControlComboBox)
{
this.Controls.AddComboBoxContentControl(NewContentControl,
"ComboBoxControl" + NewContentControl.ID);
}
}
Private Sub ThisDocument_ComboBoxContentControlAfterAdd(ByVal NewContentControl As Word.ContentControl, _
ByVal InUndoRedo As Boolean) Handles Me.ContentControlAfterAdd
If NewContentControl.Type = Word.WdContentControlType.wdContentControlComboBox Then
Me.Controls.AddComboBoxContentControl(NewContentControl, _
"ComboBoxControl" + NewContentControl.ID)
End If
End Sub
このバージョンは、.NET Framework 4 または.NET Framework 4.5 を対象とするアプリケーション レベルのアドイン用です。 このコードを使用するには、プロジェクトの ThisAddIn
クラスに貼り付けます。 また、作業中の文書の ActiveDocument_ComboBoxContentControlAfterAdd
イベントにイベント ハンドラーを ContentControlAfterAdd アタッチする必要があります。
void ActiveDocument_ComboBoxContentControlAfterAdd(
Word.ContentControl NewContentControl, bool InUndoRedo)
{
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
if (NewContentControl.Type == Word.WdContentControlType.wdContentControlComboBox)
{
vstoDoc.Controls.AddComboBoxContentControl(NewContentControl,
"ComboBoxControl" + NewContentControl.ID);
}
}
Private Sub ActiveDocument_ComboBoxContentControlAfterAdd( _
ByVal NewContentControl As Word.ContentControl, _
ByVal InUndoRedo As Boolean)
Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
If NewContentControl.Type = Word.WdContentControlType. _
wdContentControlComboBox Then
vstoDoc.Controls.AddComboBoxContentControl(NewContentControl, _
"ComboBoxControl" + NewContentControl.ID)
End If
End Sub
注釈
実行時にドキュメント内のネイティブ コンテンツ コントロールに基づく新しい ComboBoxContentControl を追加するには、このメソッドを使用します。 これは、実行時に を ComboBoxContentControl 作成し、次回ドキュメントを開いたときに同じコントロールを再作成する場合に便利です。 詳細については、「 Adding Controls to Office Documents at Run Time」を参照してください。
適用対象
AddComboBoxContentControl(Range, String)
ドキュメント内の指定した範囲に新しい ComboBoxContentControl を追加します。
public:
Microsoft::Office::Tools::Word::ComboBoxContentControl ^ AddComboBoxContentControl(Microsoft::Office::Interop::Word::Range ^ range, System::String ^ name);
public Microsoft.Office.Tools.Word.ComboBoxContentControl AddComboBoxContentControl (Microsoft.Office.Interop.Word.Range range, string name);
abstract member AddComboBoxContentControl : Microsoft.Office.Interop.Word.Range * string -> Microsoft.Office.Tools.Word.ComboBoxContentControl
Public Function AddComboBoxContentControl (range As Range, name As String) As ComboBoxContentControl
パラメーター
- name
- String
新しいコントロールの名前。
戻り値
ドキュメントに追加された ComboBoxContentControl。
例外
name
は、null
であるか、または長さがゼロです。
ControlCollection に既に同じ名前のコントロールがあります。
例
次のコード例では、ドキュメントの先頭に新しい ComboBoxContentControl を追加します。 この例では、ユーザーがコントロールで選択できる項目の一覧に、複数の色の名前も追加します。
このバージョンは、ドキュメント レベルのカスタマイズ用です。 このコードを使用するには、プロジェクトの ThisDocument
クラスに貼り付け、 メソッドから メソッドをAddComboBoxControlAtRange
ThisDocument_Startup
呼び出します。
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";
}
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
このバージョンは、.NET Framework 4 または.NET Framework 4.5 を対象とするアプリケーション レベルのアドイン用です。 このコードを使用するには、プロジェクトの ThisAddIn
クラスに貼り付け、 メソッドから メソッドをAddComboBoxControlAtRange
ThisAddIn_Startup
呼び出します。
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";
}
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
注釈
実行時にドキュメント内の指定した範囲に新しい ComboBoxContentControl を追加するには、このメソッドを使用します。 詳細については、「 Adding Controls to Office Documents at Run Time」を参照してください。