다음을 통해 공유


Label.AutoSize 속성

전체 내용이 표시되도록 컨트롤의 크기를 자동으로 조정할지 여부를 나타내는 값을 가져오거나 설정합니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
<LocalizableAttribute(True)> _
Public Overrides Property AutoSize As Boolean
‘사용 방법
Dim instance As Label
Dim value As Boolean

value = instance.AutoSize

instance.AutoSize = value
[LocalizableAttribute(true)] 
public override bool AutoSize { get; set; }
[LocalizableAttribute(true)] 
public:
virtual property bool AutoSize {
    bool get () override;
    void set (bool value) override;
}
/** @property */
public boolean get_AutoSize ()

/** @property */
public void set_AutoSize (boolean value)
public override function get AutoSize () : boolean

public override function set AutoSize (value : boolean)

속성 값

컨트롤이 해당 내용에 맞도록 너비를 조정하면 true이고 조정하지 않으면 false입니다. 기본값은 false입니다.

설명

이 속성이 true로 설정되어 있으면 Label은 해당 너비를 조정하여 컨트롤의 전체 내용을 표시합니다. Label 컨트롤을 사용하여 응용 프로그램 프로세스 상태와 같은 다양한 길이의 텍스트를 표시할 경우 일반적으로 이 속성을 true로 설정합니다. 또한 이 속성을 사용하면 응용 프로그램에서 다양한 언어의 텍스트를 표시할 수 있습니다. 텍스트 크기는 Windows의 언어 설정에 따라 달라질 수 있습니다.

중요

글꼴의 높이가 Label 높이보다 크고 AutoEllipsistrue이면 그릴 텍스트에 대해 AutoSizefalse로 설정해야 합니다.

예제

다음 예제에서는 AutoSize 속성을 보여 줍니다. 이 예제를 실행하려면 폼에 다음 코드를 붙여넣고 폼의 생성자나 Load 메서드에서 InitializeLabel 메서드를 호출합니다.

' Declare a label.
Friend WithEvents Label1 As System.Windows.Forms.Label

' Initialize the label.
Private Sub InitializeLabel()
    Me.Label1 = New Label
    Me.Label1.Location = New System.Drawing.Point(10, 10)
    Me.Label1.Name = "Label1"
    Me.Label1.TabIndex = 0

    ' Set the label to a small size, but set the AutoSize property 
    ' to true. The label will adjust its length so all the text
    ' is visible, however if the label is wider than the form,
    ' the entire label will not be visible.
    Me.Label1.Size = New System.Drawing.Size(10, 10)
    Me.Controls.Add(Me.Label1)
    Me.Label1.AutoSize = True
    Me.Label1.Text = "The text in this label is longer than the set size."

End Sub
// Declare a label.
internal System.Windows.Forms.Label Label1;

// Initialize the label.
private void InitializeLabel()
{
    this.Label1 = new Label();
    this.Label1.Location = new System.Drawing.Point(10, 10);
    this.Label1.Name = "Label1";
    this.Label1.TabIndex = 0;

    // Set the label to a small size, but set the AutoSize property 
    // to true. The label will adjust its length so all the text
    // is visible, however if the label is wider than the form,
    // the entire label will not be visible.
    this.Label1.Size = new System.Drawing.Size(10, 10);
    this.Controls.Add(this.Label1);
    this.Label1.AutoSize = true;
    this.Label1.Text = "The text in this label is longer" +  
        " than the set size.";

}
   // Declare a label.
internal:
   System::Windows::Forms::Label ^ Label1;

private:

   // Initialize the label.
   void InitializeLabel()
   {
      this->Label1 = gcnew Label;
      this->Label1->Location = System::Drawing::Point( 10, 10 );
      this->Label1->Name = "Label1";
      this->Label1->TabIndex = 0;
      
      // Set the label to a small size, but set the AutoSize property 
      // to true. The label will adjust its length so all the text
      // is visible, however if the label is wider than the form,
      // the entire label will not be visible.
      this->Label1->Size = System::Drawing::Size( 10, 10 );
      this->Controls->Add( this->Label1 );
      this->Label1->AutoSize = true;
      this->Label1->Text = "The text in this label is longer"
      " than the set size.";
   }
// Declare a label.
private System.Windows.Forms.Label label1;

// Initialize the label.
private void InitializeLabel()
{
    this.label1 = new Label();
    this.label1.set_Location(new System.Drawing.Point(10, 10));
    this.label1.set_Name("label1");
    this.label1.set_TabIndex(0);
    // Set the label to a small size, but set the AutoSize property 
    // to true. The label will adjust its length so all the text
    // is visible, however if the label is wider than the form,
    // the entire label will not be visible.
    this.label1.set_Size(new System.Drawing.Size(10, 10));
    this.get_Controls().Add(this.label1);
    this.label1.set_AutoSize(true);
    this.label1.set_Text("The text in this label is longer" 
        + " than the set size.");
} //InitializeLabel

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

Label 클래스
Label 멤버
System.Windows.Forms 네임스페이스
Control.Text 속성
PreferredHeight
PreferredWidth
Label.AutoEllipsis 속성