70-526 MCTSTextBox controlThe TextBox control displays text entered at design time that can be edited by users at run time, or changed programmatically. Typically, a TextBox control is used to display a single line of text or allow a single line of text to be input by the user. It may also be set up to display/input multiline text with scrollbars, for use such as the notepad application. Optionally it may also be set up to display a password character instead of the actual text entered. There are other properties that allow the behaviour of the TextBox to be configured in several ways such as only entering uppercase or lowercase letters. A TextBox usually has a Label associated with it. This is usually positioned to the left or the top of the TextBox. Inheritance hierarchySystem.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.TextBoxBase
System.Windows.Forms.TextBox
TextBoxBase provides the base functionality for text manipulation in a TextBox, such as selecting text, cutting to and pasting from the Clipboard. Setting MultiLine text graphicallyClicking the smart tag icon ![]() Useful propertiesAcceptsReturn - Indicates whether pressing ENTER in a multiline TextBox control creates a new line of text in the control or activates the default button for the form. AcceptsTab - Indicates whether pressing the TAB key in a multiline TextBox control types a TAB character in the control instead of moving the focus to the next control in the tab order. AutoCompleteCustomSource - Indicates the custom System.Collections.Specialized.StringCollection to use when the AutoCompleteSource property is set to CustomSource. AutoCompleteMode - Controls how automatic completion works for the TextBox. Takes a value from the AutoCompleteMode enumeration:
AutoCompleteSource - Specifies the source of complete strings used for automatic completion. Takes a value from the AutoCompleteSource enumeration:
CausesValidation - Indicates whether the control causes validation to be performed on any controls that require validation when it receives focus. CharacterCasing - Indicates whether the TextBox control modifies the case of characters as they are typed. Takes a value from the CharacterCasing enumeration:
Lines - Specifies the lines of text in a TextBox control stored as a string array. Note MaxLength - Specifies the maximum number of characters the user can type or paste into the TextBox control. Multiline - Indicates whether this is a multiline TextBox control. PasswordChar - Specifies the character used to mask characters of a password in a single-line TextBox control. ReadOnly - Indicates whether text in the TextBox control is read-only. ScrollBars - Specifies which scroll bars should appear in a multiline TextBox control. SelectedText - Indicates the currently selected text in the TextBox control. SelectionLength - Specifies the number of characters selected in the TextBox control. SelectionStart - Specifies the starting point of text selected in the TextBox control. Text - Specifies the current text in the TextBox control. TextAlign - Specifies how text is aligned in a TextBox control. TextLength - Gets the length of text in the TextBox control. UseSystemPasswordChar - Indicates whether the text in the TextBox control should appear as the default password character. WordWrap - Indicates whether a multiline TextBox control automatically wraps words to the beginning of the next line when necessary. Using AutoCompleteThree of the above properties allow the user to auto-complete text within a TextBox control. This can only happen when Multiline is set to false. ![]() In the example above, the following settings are used:
Download the above sample application (written in C# Express). Masking Characters as PasswordsThe properties PasswordChar and UseSystemPasswordChar can be used to create a TextBox that does not show the characters when they are types in. This will happen if either PasswordChar is set to a value or UseSystemPasswordChar is set to true. However, if both are set then the system password character wil be used. MSDN references
|