MultiLine Property

Applies To

TextBox control.

Description

Specifies whether a control can accept and display multiple lines of text.

Syntax

object.MultiLine [= Boolean]

The MultiLine property syntax has these parts:

Part

Description

object

Required. A valid object.

Boolean

Optional. Whether the control supports more than one line of text.


Settings

The settings for Boolean are:

Value

Description

True

The text is displayed across multiple lines (default).

False

The text is not displayed across multiple lines.


Remarks

A multiline TextBox allows absolute line breaks and adjusts its quantity of lines to accommodate the amount of text it holds. If needed, a multiline control can have vertical scroll bars.

A single-line TextBox doesn't allow absolute line breaks and doesn't use vertical scroll bars.

Single-line controls ignore the value of the WordWrap property.

Note If you change MultiLine to False in a multiline TextBox, all the characters in the TextBox will be combined into one line, including non-printing characters (such as carriage returns and new-lines).

See Also

AutoSize property, EnterKeyBehavior property, ScrollBars property, WordWrap property.

Example

The following example demonstrates the MultiLine, WordWrap, and ScrollBars properties on a TextBox.

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

  • A TextBox named TextBox1.
  • Four ToggleButton controls named ToggleButton1 through ToggleButton4.
To see the entire text placed in the TextBox, set MultiLine and WordWrap to True by clicking the ToggleButton controls.

When MultiLine is True, you can enter new lines of text by pressing SHIFT+ENTER.

ScrollBars appears when you manually change the content of the TextBox.

Private Sub UserForm_Initialize()
'Initialize TextBox properties and toggle buttons

    TextBox1.Text = "Type your text here. Enter SHIFT+ENTER to move " _
        & "to a new line."

    TextBox1.AutoSize = False
    ToggleButton1.Caption = "AutoSize Off"
    ToggleButton1.Value = False
    ToggleButton1.AutoSize = True

    TextBox1.WordWrap = False
    ToggleButton2.Caption = "WordWrap Off"
    ToggleButton2.Value = False
    ToggleButton2.AutoSize = True

    TextBox1.ScrollBars = 0
    ToggleButton3.Caption = "ScrollBars Off"
    ToggleButton3.Value = False
    ToggleButton3.AutoSize = True

    TextBox1.MultiLine = False
    ToggleButton4.Caption = "Single Line"
    ToggleButton4.Value = False
    ToggleButton4.AutoSize = True
 End Sub

Private Sub ToggleButton1_Click()
'Set AutoSize property and associated ToggleButton

    If ToggleButton1.Value = True Then
        TextBox1.AutoSize = True
        ToggleButton1.Caption = "AutoSize On"
    Else
        TextBox1.AutoSize = False
        ToggleButton1.Caption = "AutoSize Off"
    End If
End Sub

Private Sub ToggleButton2_Click()
'Set WordWrap property and associated ToggleButton

    If ToggleButton2.Value = True Then
        TextBox1.WordWrap = True
        ToggleButton2.Caption = "WordWrap On"
    Else
        TextBox1.WordWrap = False
        ToggleButton2.Caption = "WordWrap Off"
    End If
End Sub

Private Sub ToggleButton3_Click()
'Set ScrollBars property and associated ToggleButton

    If ToggleButton3.Value = True Then
        TextBox1.ScrollBars = 3
        ToggleButton3.Caption = "ScrollBars On"
    Else
        TextBox1.ScrollBars = 0
        ToggleButton3.Caption = "ScrollBars Off"
    End If
End Sub

Private Sub ToggleButton4_Click()
'Set MultiLine property and associated ToggleButton

    If ToggleButton4.Value = True Then
        TextBox1.MultiLine = True
        ToggleButton4.Caption = "Multiple Lines"
    Else
        TextBox1.MultiLine = False
        ToggleButton4.Caption = "Single Line"
    End If
End Sub