다음을 통해 공유


ControlExtensions.AddLabel 메서드 (ControlCollection, Range, Single, Single, String)

문서의 지정된 위치에 지정된 크기의 새 Label 컨트롤을 추가합니다.

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

구문

‘선언
<ExtensionAttribute> _
Public Shared Function AddLabel ( _
    controls As ControlCollection, _
    range As Range, _
    width As Single, _
    height As Single, _
    name As String _
) As Label
public static Label AddLabel(
    this ControlCollection controls,
    Range range,
    float width,
    float height,
    string name
)

매개 변수

  • controls
    형식: Microsoft.Office.Tools.Word.ControlCollection
    컨트롤을 추가할 컬렉션입니다.이 매개 변수를 직접 지정하지 마십시오.Document.Controls 속성(응용 프로그램 수준 프로젝트에서) 또는 DocumentBase.Controls 속성(문서 수준 프로젝트에서)으로 반환된 컬렉션에서 이 메서드를 호출하면 이 매개 변수가 자동으로 제공됩니다.
  • width
    형식: System.Single
    컨트롤의 너비(포인트)입니다.
  • height
    형식: System.Single
    컨트롤의 높이(포인트)입니다.

반환 값

형식: Microsoft.Office.Tools.Word.Controls.Label
문서에 추가된 컨트롤입니다.

사용 정보

Visual Basic 및 C#에서는 이 메서드를 ControlCollection 형식의 모든 개체에서 인스턴스 메서드로 호출할 수 있습니다. 인스턴스 메서드 구문을 사용하여 이 메서드를 호출할 경우에는 첫 번째 매개 변수를 생략합니다. 자세한 내용은 확장 메서드(Visual Basic) 또는 확장 메서드(C# 프로그래밍 가이드)를 참조하십시오.

예외

예외 상황
ArgumentNullException

name 또는 range 인수가 nullNull 참조(Visual Basic의 경우 Nothing)이거나 name 인수의 길이가 0인 경우

ControlNameAlreadyExistsException

이름이 같은 컨트롤이 ControlCollection 인스턴스에 있는 경우

InvalidRangeException

지정된 범위가 올바르지 않은 경우.

설명

이 메서드를 사용하면 Label 개체를 ControlCollection의 끝에 추가할 수 있습니다.

프로그래밍 방식으로 추가된 Label을 제거하려면 Remove 메서드를 사용합니다.

예제

다음 코드 예제에서는 Label 컨트롤을 문서의 첫째 단락에 추가한 다음 텍스트를 First Name으로 변경합니다. 이 예제를 사용하려면 문서 수준 프로젝트 ThisDocument 클래스에서 실행하십시오.

Private Sub WordRangeAddLabel()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim Label1 As Microsoft.Office.Tools.Word.Controls.Label _
        = Me.Controls.AddLabel(Me.Paragraphs(1).Range, 75, _
            17.25F, "Label1")
    Label1.Text = "First Name"
End Sub 
private void WordRangeAddLabel()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Controls.Label
        label1 = this.Controls.AddLabel(
        this.Paragraphs[1].Range, 75, 17.25F, "label1");
    label1.Text = "First Name";
}

.NET Framework 보안

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

참고 항목

참조

ControlExtensions 클래스

AddLabel 오버로드

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