TextBoxBase.AutoSize Property

This property supports the .NET Framework infrastructure and is not intended to be used directly from your code.

Gets or sets a value indicating whether the height of the control automatically adjusts when the font assigned to the control is changed.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public override bool AutoSize { get; set; }
/** @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)

Not applicable.

Property Value

true if the height of the control automatically adjusts when the font is changed; otherwise, false. The default is true.

When you set the AutoSize property to true for a TextBox, when the Font changes, the TextBox expands or contracts the Height to accommodate the larger or smaller text. The Width of the TextBox does not change.

If you want to change the size of the control as the user enters text, you can use a RichTextBox control and use its ContentsResized event to change its size.

This example assumes that you have a form with two text boxes, two buttons, and click events for each of the buttons. The example demonstrates the AutoSize property by setting it to true for one text box and false for the other. When you click one button the text boxes are filled with a smaller text, and when you click the other button the text boxes are filled with larger text. The text box that has AutoSize set to true expands in height to accommodate the larger text. The width does not change.

Windows 98, Windows Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions