Поделиться через


How to: View Multiple Lines in the Windows Forms TextBox Control

By default, the Windows Forms TextBox control displays a single line of text and does not display scroll bars. If the text is longer than the available space, only part of the text is visible. You can change this default behavior by setting the Multiline, WordWrap, and ScrollBars properties to appropriate values.

To display a carriage return in the TextBox control

  • To display a carriage return in a multi-line TextBox, use the NewLine property.

    Be aware that the interpretation of escape characters (\) is language-specific. Visual Basic uses Chr$(13) & Chr$(10) for the carriage return and linefeed character combination.

To view multiple lines in the TextBox control

  1. Set the Multiline property to true. If WordWrap is true (the default), then the text in the control will appear as one or more paragraphs; otherwise it will appear as a list, in which some lines may be clipped at the edge of the control.

  2. Set the ScrollBars property to an appropriate value.

    Value

    Description

    None

    Use this value if the text will be a paragraph that almost always fits the control. The user can use the mouse pointer to move around inside the control if the text is too long to display all at once.

    Horizontal

    Use this value if you want to display a list of lines, some of which may be longer than the width of the TextBox control.

    Both

    Use this value if the list may be longer than the height of the control.

  3. Set the WordWrap property to an appropriate value.

    Value

    Description

    false

    Text in the control will not automatically be wrapped, so it will scroll to the right until a line break is reached. Use this value if you chose Horizontal scroll bars or Both, above.

    true (default)

    The horizontal scrollbar will not appear. Use this value if you chose Vertical scroll bars or None, above, to display one or more paragraphs.

See Also

Tasks

How to: Control the Insertion Point in a Windows Forms TextBox Control

How to: Create a Password Text Box with the Windows Forms TextBox Control

How to: Create a Read-Only Text Box (Windows Forms)

How to: Put Quotation Marks in a String (Windows Forms)

How to: Select Text in the Windows Forms TextBox Control

Reference

TextBox Control Overview (Windows Forms)

TextBox

Other Resources

TextBox Control (Windows Forms)