Share via


ControlCollection.AddComboBoxContentControl 메서드

정의

오버로드

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입니다.

예외

namenull이거나 길이가 0입니다.

ControlCollection에 동일한 이름의 컨트롤이 이미 있습니다.

예제

다음 코드 예제에서는 문서의 시작 부분에 새 ComboBoxContentControl 를 추가합니다. 또한 이 예제에서는 사용자가 컨트롤에서 선택할 수 있는 항목 목록에 여러 색의 이름을 추가합니다.

이 버전은 문서 수준 사용자 지정을 위한 것입니다. 이 코드를 사용하려면 프로젝트의 클래스에 ThisDocument 붙여넣고 메서드에서 메서드를 AddComboBoxControlAtSelectionThisDocument_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 붙여넣고 메서드에서 메서드를 AddComboBoxControlAtSelectionThisAddIn_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입니다.

예외

contentControlnull.-또는- namenull 거나 길이가 0입니다.

ControlCollection에 동일한 이름의 컨트롤이 이미 있습니다.

contentControl은 문서 블록 갤러리가 아닙니다(즉, TypecontentControl 속성에 Microsoft.Office.Interop.Word 값이 없습니다. WdContentControlType.wdContentControlComboBox).

예제

다음 코드 예제에서는 문서에 이미 있는 모든 네이티브 콤보 상자에 대해 새 ComboBoxContentControl 를 만듭니다.

이 버전은 문서 수준 사용자 지정을 위한 것입니다. 이 코드를 사용하려면 프로젝트의 클래스에 ThisDocument 붙여넣고 메서드에서 메서드를 CreateComboBoxControlsFromNativeControlsThisDocument_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 붙여넣고 메서드에서 메서드를 CreateComboBoxControlsFromNativeControlsThisAddIn_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#의 경우 이벤트 처리기를 ContentControlAfterAdd 클래스의 ThisDocument 이벤트에 연결 ThisDocument_ComboBoxContentControlAfterAdd 해야 합니다.

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 붙여넣습니다. 또한 이벤트 처리기를 ContentControlAfterAdd 현재 문서의 이벤트에 연결 ActiveDocument_ComboBoxContentControlAfterAdd 해야 합니다.

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

매개 변수

range
Range

새 컨트롤의 범위를 제공하는 Range입니다.

name
String

새 컨트롤의 이름입니다.

반환

문서에 추가된 ComboBoxContentControl입니다.

예외

namenull이거나 길이가 0입니다.

ControlCollection에 동일한 이름의 컨트롤이 이미 있습니다.

예제

다음 코드 예제에서는 문서의 시작 부분에 새 ComboBoxContentControl 를 추가합니다. 또한 이 예제에서는 사용자가 컨트롤에서 선택할 수 있는 항목 목록에 여러 색의 이름을 추가합니다.

이 버전은 문서 수준 사용자 지정을 위한 것입니다. 이 코드를 사용하려면 프로젝트의 클래스에 ThisDocument 붙여넣고 메서드에서 메서드를 AddComboBoxControlAtRangeThisDocument_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 붙여넣고 메서드에서 메서드를 AddComboBoxControlAtRangeThisAddIn_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을 참조하세요.

적용 대상