Share via


ControlCollection.AddPlainTextContentControl 메서드

정의

오버로드

AddPlainTextContentControl(String)

문서의 현재 선택 영역에서 새 PlainTextContentControl을 추가합니다.

AddPlainTextContentControl(ContentControl, String)

문서의 네이티브 콘텐츠 컨트롤을 기반으로 하는 새 PlainTextContentControl을 추가합니다.

AddPlainTextContentControl(Range, String)

문서의 지정된 범위에 새 PlainTextContentControl을 추가합니다.

AddPlainTextContentControl(String)

문서의 현재 선택 영역에서 새 PlainTextContentControl을 추가합니다.

public:
 Microsoft::Office::Tools::Word::PlainTextContentControl ^ AddPlainTextContentControl(System::String ^ name);
public Microsoft.Office.Tools.Word.PlainTextContentControl AddPlainTextContentControl (string name);
abstract member AddPlainTextContentControl : string -> Microsoft.Office.Tools.Word.PlainTextContentControl
Public Function AddPlainTextContentControl (name As String) As PlainTextContentControl

매개 변수

name
String

새 컨트롤의 이름입니다.

반환

문서에 추가된 PlainTextContentControl입니다.

예외

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

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

예제

다음 코드 예제에서는 문서의 시작 부분에 새 PlainTextContentControl 를 추가합니다.

이 버전은 문서 수준 사용자 지정을 위한 것입니다. 이 코드를 사용하려면 프로젝트의 클래스에 ThisDocument 붙여넣고 메서드에서 메서드를 AddTextControlAtSelectionThisDocument_Startup 호출합니다.

private Microsoft.Office.Tools.Word.PlainTextContentControl textControl1;

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

    textControl1 = this.Controls.AddPlainTextContentControl("textControl1");
    textControl1.PlaceholderText = "Enter your first name";
}
Dim plainTextControl1 As Microsoft.Office.Tools.Word.PlainTextContentControl

Private Sub AddPlainTextControlAtSelection()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Select()
    plainTextControl1 = Me.Controls.AddPlainTextContentControl("plainTextControl1")
    plainTextControl1.PlaceholderText = "Enter your first name"
End Sub

이 버전은 .NET Framework 4 또는 .NET Framework 4.5를 대상으로 하는 애플리케이션 수준 추가 기능용입니다. 이 코드를 사용하려면 프로젝트의 클래스에 ThisAddIn 붙여넣고 메서드에서 메서드를 AddTextControlAtSelectionThisAddIn_Startup 호출합니다.

private Microsoft.Office.Tools.Word.PlainTextContentControl textControl1;

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

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

    textControl1 = vstoDoc.Controls.AddPlainTextContentControl("textControl1");
    textControl1.PlaceholderText = "Enter your first name";
}
Dim plainTextControl1 As Microsoft.Office.Tools.Word.PlainTextContentControl

Private Sub AddPlainTextControlAtSelection()
    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()
    plainTextControl1 = vstoDoc.Controls.AddPlainTextContentControl("plainTextControl1")
    plainTextControl1.PlaceholderText = "Enter your first name"
End Sub

설명

이 메서드를 사용하여 런타임에 문서의 현재 선택 영역에 새 PlainTextContentControl 를 추가합니다. 자세한 내용은 Adding Controls to Office Documents at Run Time을 참조하세요.

적용 대상

AddPlainTextContentControl(ContentControl, String)

문서의 네이티브 콘텐츠 컨트롤을 기반으로 하는 새 PlainTextContentControl을 추가합니다.

public:
 Microsoft::Office::Tools::Word::PlainTextContentControl ^ AddPlainTextContentControl(Microsoft::Office::Interop::Word::ContentControl ^ contentControl, System::String ^ name);
public Microsoft.Office.Tools.Word.PlainTextContentControl AddPlainTextContentControl (Microsoft.Office.Interop.Word.ContentControl contentControl, string name);
abstract member AddPlainTextContentControl : Microsoft.Office.Interop.Word.ContentControl * string -> Microsoft.Office.Tools.Word.PlainTextContentControl
Public Function AddPlainTextContentControl (contentControl As ContentControl, name As String) As PlainTextContentControl

매개 변수

contentControl
ContentControl

새 컨트롤에 대한 기준인 ContentControl입니다.

name
String

새 컨트롤의 이름입니다.

반환

문서에 추가된 PlainTextContentControl입니다.

예외

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

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

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

예제

다음 코드 예제에서는 문서에 있는 모든 네이티브 일반 텍스트 컨트롤에 대해 새 PlainTextContentControl 를 만듭니다.

이 버전은 문서 수준 사용자 지정을 위한 것입니다. 이 코드를 사용하려면 프로젝트의 클래스에 ThisDocument 붙여넣고 메서드에서 메서드를 CreateTextControlsFromNativeControlsThisDocument_Startup 호출합니다.

private System.Collections.Generic.List<Microsoft.Office.Tools.Word.PlainTextContentControl> plainTextControls;

private void CreateTextControlsFromNativeControls()
{
    if (this.ContentControls.Count <= 0)
        return;

    plainTextControls = new System.Collections.Generic.List
        <Microsoft.Office.Tools.Word.PlainTextContentControl>();
    int count = 0;

    foreach (Word.ContentControl nativeControl in this.ContentControls)
    {
        if (nativeControl.Type == Word.WdContentControlType.wdContentControlText)
        {
            count++;
            Microsoft.Office.Tools.Word.PlainTextContentControl tempControl =
                this.Controls.AddPlainTextContentControl(nativeControl,
                "VSTOPlainTextContentControl" + count.ToString());
            plainTextControls.Add(tempControl);
        }
    }
}
Private plainTextControls As New System.Collections.Generic.List _
    (Of Microsoft.Office.Tools.Word.PlainTextContentControl)

Private Sub CreatePlainTextControlsFromNativeControls()
    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.wdContentControlText Then
            count += 1
            Dim tempControl As Microsoft.Office.Tools.Word.PlainTextContentControl = _
                Me.Controls.AddPlainTextContentControl(nativeControl, _
                "VSTOPlainTextContentControl" + count.ToString())
            plainTextControls.Add(tempControl)
        End If
    Next nativeControl
End Sub

이 버전은 .NET Framework 4 또는 .NET Framework 4.5를 대상으로 하는 애플리케이션 수준 추가 기능용입니다. 이 코드를 사용하려면 프로젝트의 클래스에 ThisAddIn 붙여넣고 메서드에서 메서드를 CreateTextControlsFromNativeControlsThisAddIn_Startup 호출합니다.

private System.Collections.Generic.List<Microsoft.Office.Tools.Word.PlainTextContentControl> plainTextControls;

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

    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    if (vstoDoc.ContentControls.Count <= 0)
        return;

    plainTextControls = new System.Collections.Generic.List
        <Microsoft.Office.Tools.Word.PlainTextContentControl>();
    int count = 0;

    foreach (Word.ContentControl nativeControl in vstoDoc.ContentControls)
    {
        if (nativeControl.Type == Word.WdContentControlType.wdContentControlText)
        {
            count++;
            Microsoft.Office.Tools.Word.PlainTextContentControl tempControl =
                vstoDoc.Controls.AddPlainTextContentControl(nativeControl,
                "VSTOPlainTextContentControl" + count.ToString());
            plainTextControls.Add(tempControl);
        }
    }
}
Private plainTextControls As New System.Collections.Generic.List _
    (Of Microsoft.Office.Tools.Word.PlainTextContentControl)

Private Sub CreatePlainTextControlsFromNativeControls()
    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.wdContentControlText Then
            count += 1
            Dim tempControl As Microsoft.Office.Tools.Word.PlainTextContentControl = _
                vstoDoc.Controls.AddPlainTextContentControl(nativeControl, _
                "VSTOPlainTextContentControl" + count.ToString())
            plainTextControls.Add(tempControl)
        End If
    Next nativeControl
End Sub

다음 코드 예제에서는 사용자가 문서에 추가하는 모든 네이티브 일반 텍스트 컨트롤에 대해 새 PlainTextContentControl 를 만듭니다.

이 버전은 문서 수준 사용자 지정을 위한 것입니다. 이 코드를 사용하려면 프로젝트의 클래스에 ThisDocument 붙여넣습니다. C#의 경우 이벤트 처리기를 ContentControlAfterAdd 클래스의 ThisDocument 이벤트에 연결 ThisDocument_PlainTextContentControlAfterAdd 해야 합니다.

void ThisDocument_PlainTextContentControlAfterAdd(Word.ContentControl NewContentControl, bool InUndoRedo)
{
    if (NewContentControl.Type == Word.WdContentControlType.wdContentControlText)
    {
        this.Controls.AddPlainTextContentControl(NewContentControl,
            "PlainTextControl" + NewContentControl.ID);
    }
}
Private Sub ThisDocument_PlainTextContentControlAfterAdd(ByVal NewContentControl As Word.ContentControl, _
    ByVal InUndoRedo As Boolean) Handles Me.ContentControlAfterAdd

    If NewContentControl.Type = Word.WdContentControlType.wdContentControlText Then
        Me.Controls.AddPlainTextContentControl(NewContentControl, _
            "PlainTextControl" + NewContentControl.ID)
    End If
End Sub

이 버전은 .NET Framework 4 또는 .NET Framework 4.5를 대상으로 하는 애플리케이션 수준 추가 기능용입니다. 이 코드를 사용하려면 프로젝트의 클래스에 ThisAddIn 붙여넣습니다. 또한 활성 문서의 이벤트에 이벤트 처리기를 ContentControlAfterAdd 연결 ActiveDocument_PlainTextContentControlAfterAdd 해야 합니다.

void ActiveDocument_PlainTextContentControlAfterAdd(
    Word.ContentControl NewContentControl, bool InUndoRedo)
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    if (NewContentControl.Type == Word.WdContentControlType.wdContentControlText)
    {
        vstoDoc.Controls.AddPlainTextContentControl(NewContentControl,
            "PlainTextControl" + NewContentControl.ID);
    }
}
Private Sub ActiveDocument_PlainTextContentControlAfterAdd( _
    ByVal NewContentControl As Word.ContentControl, _
    ByVal InUndoRedo As Boolean)

    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    If NewContentControl.Type = Word.WdContentControlType. _
        wdContentControlText Then
        vstoDoc.Controls.AddPlainTextContentControl(NewContentControl, _
            "PlainTextControl" + NewContentControl.ID)
    End If
End Sub

설명

이 메서드를 사용하여 런타임에 문서의 네이티브 콘텐츠 컨트롤을 기반으로 하는 새 PlainTextContentControl 를 추가합니다. 이 기능은 런타임에 를 PlainTextContentControl 만들고 다음에 문서를 열 때 동일한 컨트롤을 다시 만들려고 할 때 유용합니다. 자세한 내용은 Adding Controls to Office Documents at Run Time을 참조하세요.

적용 대상

AddPlainTextContentControl(Range, String)

문서의 지정된 범위에 새 PlainTextContentControl을 추가합니다.

public:
 Microsoft::Office::Tools::Word::PlainTextContentControl ^ AddPlainTextContentControl(Microsoft::Office::Interop::Word::Range ^ range, System::String ^ name);
public Microsoft.Office.Tools.Word.PlainTextContentControl AddPlainTextContentControl (Microsoft.Office.Interop.Word.Range range, string name);
abstract member AddPlainTextContentControl : Microsoft.Office.Interop.Word.Range * string -> Microsoft.Office.Tools.Word.PlainTextContentControl
Public Function AddPlainTextContentControl (range As Range, name As String) As PlainTextContentControl

매개 변수

range
Range

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

name
String

새 컨트롤의 이름입니다.

반환

문서에 추가된 PlainTextContentControl입니다.

예외

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

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

예제

다음 코드 예제에서는 문서의 시작 부분에 새 PlainTextContentControl 를 추가합니다.

이 버전은 문서 수준 사용자 지정을 위한 것입니다. 이 코드를 사용하려면 프로젝트의 클래스에 ThisDocument 붙여넣고 메서드에서 메서드를 AddTextControlAtRangeThisDocument_Startup 호출합니다.

private Microsoft.Office.Tools.Word.PlainTextContentControl textControl2;

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

    textControl2 = this.Controls.AddPlainTextContentControl(this.Paragraphs[1].Range,
        "textControl2");
    textControl2.PlaceholderText = "Enter your first name";
}
Dim plainTextControl2 As Microsoft.Office.Tools.Word.PlainTextContentControl

Private Sub AddPlainTextControlAtRange()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    plainTextControl2 = Me.Controls.AddPlainTextContentControl(Me.Paragraphs(1).Range, "plainTextControl2")
    plainTextControl2.PlaceholderText = "Enter your first name"
End Sub

이 버전은 .NET Framework 4 또는 .NET Framework 4.5를 대상으로 하는 애플리케이션 수준 추가 기능용입니다. 이 코드를 사용하려면 프로젝트의 클래스에 ThisAddIn 붙여넣고 메서드에서 메서드를 AddTextControlAtRangeThisAddIn_Startup 호출합니다.

private Microsoft.Office.Tools.Word.PlainTextContentControl textControl2;

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

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

    textControl2 = vstoDoc.Controls.AddPlainTextContentControl(
        vstoDoc.Paragraphs[1].Range,
        "textControl2");
    textControl2.PlaceholderText = "Enter your first name";
}
Dim plainTextControl2 As Microsoft.Office.Tools.Word.PlainTextContentControl

Private Sub AddPlainTextControlAtRange()
    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()
    plainTextControl2 = vstoDoc.Controls.AddPlainTextContentControl( _
        vstoDoc.Paragraphs(1).Range, "plainTextControl2")
    plainTextControl2.PlaceholderText = "Enter your first name"
End Sub

설명

이 메서드를 PlainTextContentControl 사용하여 런타임에 문서의 지정된 범위에 새 를 추가합니다. 자세한 내용은 Adding Controls to Office Documents at Run Time을 참조하세요.

적용 대상