MaxLength

This property returns and sets a value that indicates whether there is a maximum number of characters that can be entered in the TextBox control. If there is a maximum number, MaxLength specifies that number.

Syntax

object.MaxLength [= value]

Parameters

object
Object expression that evaluates to a TextBox control.
value
Integer that specifies the maximum number of characters a user can enter in a TextBox control. The default for the MaxLength property is 0. This default indicates a maximum created by memory constraints on the user's system for single-line TextBox controls and a maximum of approximately 32 KB for multiple-line TextBox controls. Any number greater than 0 indicates the maximum number of characters.

Remarks

Use the MaxLength property to limit the number of characters a user can enter in a TextBox.

In double-byte character set (DBCS) systems, each character can take up to two bytes instead of only one, which limits the number of characters you can enter.

If you assign text that exceeds the MaxLength property setting to a TextBox from code, no error occurs. However, only the maximum number of characters are assigned to the Text property, and extra characters are truncated. Changing this property does not affect the current contents of a TextBox, but will affect any subsequent changes to the contents.