Represents a Windows text box control.
Object
MarshalByRefObject
MarshalByRefComponent
Control
RichControl
FormatControl
TextBoxBase
TextBox
[Visual Basic] Public Class TextBox Inherits TextBoxBase [C#] public class TextBox : TextBoxBase [C++] public __gc class TextBox : public TextBoxBase [JScript] public class TextBox extends TextBoxBase
The TextBox control allows the user to enter text in an application. This control has additional functionality that is not found in the standard Windows text box control, including multiline editing and password character masking.
Typically, a TextBox control is used to display or accept as input, a single line of text. You can use the Multiline and ScrollBars properties to allow mutliple lines of text to be displayed or entered. You can also use the ScrollBars property to allow for navigation in a multiline TextBox control. Set the AcceptsTab and AcceptsReturn properties to true to allow greater text manipulation in a multiline TextBox control.
You can limit the amount of text in a TextBox control by setting the MaxLength property to a set number of characters. TextBox contols can also be used to accept passwords and other sensitive information. You can use the PasswordChar property to mask characters entered in the control.
To restrict text from being entered ina TextBox control, you can create an event handler for the OnKeyDown event in order to validate each character entered in the control. You can also restrict all entry of data in a TextBox control by setting the ReadOnly property to true.
Note Most of the functionality of the TextBox control is inherited from the TextBoxBase class.
Namespace: System.WinForms
Assembly: System.WinForms.dll
The following example creates a multiline TextBox control with vertical scroll bars. This example uses the AcceptsTab, AcceptsReturn, and WordWrap properties to make the multiline text box control useful for creating text documents.
[Visual Basic]
Public Sub CreateMultilineTextBox() ' Create an instance of a TextBox control Dim Text1 as TextBox Set Text1 = New TextBox() ' Set the Multiline property to True. Text1.Multiline = True ' Add vertical scroll bars to the TextBox control. Text1.Scrollbars = ScrollBars.Vertical ' Allow the RETURN key in the TextBox control. Text1.AcceptsReturn = True ' Allow the TAB key to be entered in the TextBox control. Text1.AcceptsTab = True ' Set WordWrap to True to allow text to wrap to the next line. Text1.WordWrap = True ' Set the default text of the control. Text1.Text = "Welcome!" End Sub