TextBoxBase.AutoSize 속성

정의

컨트롤에 할당된 글꼴이 변경될 때 컨트롤의 높이가 자동으로 조정되는지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 virtual property bool AutoSize { bool get(); void set(bool value); };
public virtual bool AutoSize { get; set; }
[System.ComponentModel.Browsable(false)]
public override bool AutoSize { get; set; }
member this.AutoSize : bool with get, set
[<System.ComponentModel.Browsable(false)>]
member this.AutoSize : bool with get, set
Public Overridable Property AutoSize As Boolean
Public Overrides Property AutoSize As Boolean

속성 값

글꼴이 변경될 때 컨트롤의 높이가 자동으로 조정되면 true이고, 그렇지 않으면 false입니다. 기본값은 true입니다.

특성

예제

이 예제에서는 두 개의 텍스트 상자, 두 개의 단추 및 각 단추에 대한 클릭 이벤트가 있는 폼이 있다고 가정합니다. 이 예제에서는 AutoSize 속성을 한 텍스트 상자와 false 다른 텍스트 상자에 대해 로 true 설정하여 보여 줍니다. 한 단추를 클릭하면 텍스트 상자가 더 작은 텍스트로 채워지고 다른 단추를 클릭하면 텍스트 상자가 더 큰 텍스트로 채워집니다. 로 설정된 true 텍스트 상자는 AutoSize 더 큰 텍스트를 수용할 수 있도록 높이가 확장됩니다. 너비가 변경되지 않습니다.

private void button1_Click(object sender, EventArgs e)
{
    this.textBox1.AutoSize = true;
    this.textBox1.Text = "Hello world!";
    this.textBox1.Font = new System.Drawing.Font("Arial", 10, FontStyle.Regular);

    this.textBox2.AutoSize = false;
    this.textBox2.Text = "Hello world!";
    this.textBox2.Font = new System.Drawing.Font("Arial", 10, FontStyle.Regular);
}

private void button2_Click(object sender, EventArgs e)
{
    this.textBox1.AutoSize = true;
    this.textBox1.Text = "Goodbye world!";
    this.textBox1.Font = new System.Drawing.Font("ArialBlack", 14, FontStyle.Regular);

    this.textBox2.AutoSize = false;
    this.textBox2.Text = "Goodbye world!";
    this.textBox2.Font = new System.Drawing.Font("ArialBlack", 14, FontStyle.Regular);
}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Me.TextBox1.AutoSize = True
    Me.TextBox1.Text = "Hello world!"
    Me.TextBox1.Font = New System.Drawing.Font("Arial", 10, FontStyle.Regular)

    Me.TextBox2.AutoSize = False
    Me.TextBox2.Text = "Hello world!"
    Me.TextBox2.Font = New System.Drawing.Font("Arial", 10, FontStyle.Regular)
End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    Me.TextBox1.AutoSize = True
        Me.TextBox1.Text = "Goodbye world!"
    Me.TextBox1.Font = New System.Drawing.Font("ArialBlack", 14, FontStyle.Regular)

    Me.TextBox2.AutoSize = False
        Me.TextBox2.Text = "Goodbye world!"
    Me.TextBox2.Font = New System.Drawing.Font("ArialBlack", 14, FontStyle.Regular)
End Sub

설명

에 대해 속성을 로 설정 AutoSize 하면 가 Font 변경 TextBox 되면 가 더 크거나 작은 텍스트를 수용하도록 를 확장하거나 계약합니다Height.trueTextBox 의 는 WidthTextBox 변경되지 않습니다.

사용자가 텍스트를 입력할 때 컨트롤의 크기를 변경하려는 경우 컨트롤을 RichTextBox 사용하고 해당 ContentsResized 이벤트를 사용하여 크기를 변경할 수 있습니다.

적용 대상