Share via


DocumentBase.SelectContentControlsByTag 메서드

문서에서 지정된 태그가 있는 모든 콘텐츠 컨트롤을 반환합니다.

네임스페이스:  Microsoft.Office.Tools.Word
어셈블리:  Microsoft.Office.Tools.Word.v4.0.Utilities(Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

구문

‘선언
Public Function SelectContentControlsByTag ( _
    tag As String _
) As ContentControls
public ContentControls SelectContentControlsByTag(
    string tag
)

매개 변수

  • tag
    형식: System.String
    반환할 콘텐츠 컨트롤의 태그입니다.

반환 값

형식: Microsoft.Office.Interop.Word.ContentControls
지정된 태그가 있는 콘텐츠 컨트롤이 들어 있는 ContentControls 컬렉션입니다.

예제

다음 코드 예제에서는 문서에 세 개의 단락을 추가한 다음 이 새 단락에 각각 RichTextContentControl, ComboBoxContentControlDropDownListContentControl 컨트롤을 추가합니다. 또한 이 예제에서는 각 컨트롤의 Tag 및 Title 속성을 설정합니다. 그런 다음 SelectContentControlsByTag 메서드를 호출하여 태그 값이 Customer인 네이티브 콘텐츠 컨트롤의 컬렉션을 가져오고 반환된 컬렉션에 있는 각 컨트롤의 제목을 메시지 상자에 표시합니다. 이 예제를 사용하려면 문서 수준 프로젝트 ThisDocument 클래스에서 실행하십시오.

Private Sub ContentControlsTag()
    Dim par1 As Word.Paragraph = Me.Paragraphs.Add()
    Dim richTextControl As  _
        Microsoft.Office.Tools.Word.RichTextContentControl = _
        Me.Controls.AddRichTextContentControl(par1.Range, "richTextControl")
    richTextControl.Tag = "Customer"
    richTextControl.Title = "Customer Name"

    Dim par2 As Word.Paragraph = Me.Paragraphs.Add()
    Dim comboBoxControl As  _
        Microsoft.Office.Tools.Word.ComboBoxContentControl = _
        Me.Controls.AddComboBoxContentControl(par2.Range, "comboBoxControl")
    comboBoxControl.Tag = "Customer"
    comboBoxControl.Title = "Customer Title"

    Dim par3 As Word.Paragraph = Me.Paragraphs.Add()
    Dim dropDownListControl As  _
        Microsoft.Office.Tools.Word.DropDownListContentControl = _
        Me.Controls.AddDropDownListContentControl(par3.Range, _
            "dropDownListControl")
    dropDownListControl.Tag = "Products"
    dropDownListControl.Title = "List of Products"

    Dim relatedControls As Word.ContentControls = _
        Me.SelectContentControlsByTag("Customer")
    MessageBox.Show("Displaying all controls with a Tag value of" + _
                    " 'Customer'. Click OK to continue.")
    For Each ctrl As Word.ContentControl In relatedControls
        MessageBox.Show("Control title: " + ctrl.Title)
    Next
End Sub
private void ContentControlsTag()
{
    Word.Paragraph par1 = this.Paragraphs.Add(ref missing);
    Microsoft.Office.Tools.Word.RichTextContentControl richTextControl =
        this.Controls.AddRichTextContentControl(par1.Range, 
        "richTextControl");
    richTextControl.Tag = "Customer";
    richTextControl.Title = "Customer Name";

    Word.Paragraph par2 = this.Paragraphs.Add(ref missing);
    Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl =
        this.Controls.AddComboBoxContentControl(par2.Range, 
        "comboBoxControl");
    comboBoxControl.Tag = "Customer";
    comboBoxControl.Title = "Customer Title";

    Word.Paragraph par3 = this.Paragraphs.Add(ref missing);
    Microsoft.Office.Tools.Word.DropDownListContentControl 
        dropDownListControl = this.Controls.AddDropDownListContentControl(
        par3.Range, "dropDownListControl");
    dropDownListControl.Tag = "Products";
    dropDownListControl.Title = "List of Products";

    Word.ContentControls relatedControls = 
        this.SelectContentControlsByTag("Customer");
    MessageBox.Show("Displaying all controls with a Tag value of" + 
        " 'Customer'. Click OK to continue.");
    foreach (Word.ContentControl ctrl in relatedControls)
    {
        MessageBox.Show("Control title: " + ctrl.Title);
    }
}

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

DocumentBase 클래스

Microsoft.Office.Tools.Word 네임스페이스