TextBox Control

The text box control is used to display information entered by the user at run time, or assigned to the Text property of the control at design or run time.

Syntax

TextBox

The TextBox control has the following properties, methods, and events.

Properties Methods Events
Alignment Move Change
Appearance Refresh Click
BackColor, ForeColor SetFocus DblClick
BorderStyle ZOrder GotFocus
Container KeyDown, KeyUp
Enabled KeyPress
Font LostFocus
FontBold MouseDown, MouseUp
FontItalic MouseMove
FontStrikethru
FontUnderline
FontName
FontSize
Height, Width
HideSelection
HWnd
Left, Top
Locked
MaxLength
MultiLine
Name
Parent
PasswordChar
ScrollBars
SelLength, SelStart, SelText
TabIndex
TabStop
Tag
Text
Visible

Remarks

In general, the TextBox control should be used for editable text, although you can make it read-only by setting its Locked property to True. Text boxes also allow you to display multiple lines, to wrap text to the size of the control, and to add basic formatting.

Text entered into the text box control is contained in the Text property. By default, you can enter up to 2048 characters in a text box. If you set the MultiLine property of the control to True, you can enter up to 32K of text.

To display multiple lines of text in a TextBox control, set the MultiLine property to True. If a multiple-line TextBox doesn't have a horizontal scroll bar, text wraps automatically even when the TextBox is resized. To customize the scroll bar combination on a TextBox, set the ScrollBars property.

Scroll bars will always appear on the TextBox when its MultiLine property is set to True, and its ScrollBars property is set to anything except None (0).

If you set the MultiLine property to True, you can use the Alignment property to set the alignment of text within the TextBox. The text is left-justified by default. If the MultiLine property is False, setting the Alignment property has no effect.