AutoSize Property

Applies To

CheckBox control, ComboBox control, CommandButton control, Image control, Label control, OptionButton control, TextBox control, ToggleButton control.

Description

Specifies whether an object automatically resizes to display its entire contents.

Syntax

object.AutoSize [= Boolean]

The AutoSize property syntax has these parts:

Part

Description

object

Required. A valid object.

Boolean

Optional. Whether the control is resized.


Settings

The settings for Boolean are:

Value

Description

True

Automatically resizes the control to display its entire contents.

False

Keeps the size of the control constant. Contents are clipped when they exceed the area of the control (default).


Remarks

For controls with captions, the AutoSize property specifies whether the control automatically adjusts to display the entire caption.

For controls without captions, this property specifies whether the control automatically adjusts to display the information stored in the control. In a ComboBox, for example, setting AutoSize to True automatically sets the width of the display area to match the length of the current text.

For a single-line text box, setting AutoSize to True automatically sets the width of the display area to the length of the text in the text box.

For a multiline text box that contains no text, setting AutoSize to True automatically displays the text as a column. The width of the text column is set to accommodate the widest letter of that font size. The height of the text column is set to display the entire text of the TextBox.

For a multiline text box that contains text, setting AutoSize to True automatically enlarges the TextBox vertically to display the entire text. The width of the TextBox does not change.

Note If you manually change the size of a control while AutoSize is True, the manual change overrides the size previously set by AutoSize.

See Also

Caption property, MultiLine property, WordWrap property.

Example

The following example demonstrates the effects of the AutoSize property with a single-line TextBox and a multiline TextBox. The user can enter text into either TextBox and turn AutoSize on or off independently of the contents of the TextBox. This code sample also uses the Text property.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • Two TextBox controls named TextBox1 and TextBox2.
  • A ToggleButton named ToggleButton1.
    Private Sub UserForm_Initialize()
        TextBox1.Text = "Single-line TextBox. Type your text here."
        
        TextBox2.MultiLine = True
        TextBox2.Text = "Multi-line TextBox. Type your text here. " _
           & "Use CTRL+ENTER to start a new line."
        
        ToggleButton1.Value = True
        ToggleButton1.Caption = "AutoSize On"
        TextBox1.AutoSize = True
        TextBox2.AutoSize = True
    End Sub
    
    Private Sub ToggleButton1_Click()
        If ToggleButton1.Value = True Then
            ToggleButton1.Caption = "AutoSize On"
            TextBox1.AutoSize = True
            TextBox2.AutoSize = True
        Else
            ToggleButton1.Caption = "AutoSize Off"
            TextBox1.AutoSize = False
            TextBox2.AutoSize = False
        End If
    End Sub