NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

TextBoxBase.MaxLength

Gets or sets the maximum number of characters the user can type into the text box control.

[Visual Basic]
Overridable Public Property MaxLength As Integer
[C#]
public int MaxLength {virtual get; virtual set;}
[C++]
public: __property virtual int get_MaxLength();
public: __property virtual void set_MaxLength(int);
[JScript]
public function get MaxLength() : int;
public function set MaxLength(int);

Property Value

The number of characters that can be entered into the control. The default is zero.

Remarks

When this property is set to zero, the maximum length of the text that can be entered in the control is limited only by available memory. You can use this property to restrict the length of text entered in the control for values such as postal codes and telephone numbers. You can also use this property to restrict the length of text entered when the data is to be entered in a database. You can limit the text entered into the control to the maximum length of the corresponding field in the database.

Example [Visual Basic]

The following example creates a TextBox control that is used to accept a password. This example uses the CharacterCasing property to force all characters typed into the TextBox control to uppercase and the MaxLength property to restrict the password length to eight characters. This example also uses the TextAlign property to align the password entry to the center of the TextBox control.

[Visual Basic]

Public Sub CreatePasswordTextBox()
   ' Create an instance of the TextBox control.
   Dim TextBox1 as TextBox
   Set TextBox1 = New TextBox
   'TextBox1.MaxLength = 8
   ' Assign the asterick character as the password character.
   TextBox1.PasswordChar = "*"
   ' Force all text entered to be lower-cased.
   TextBox1.CharacterCasing = CharacterCasing.Upper
   ' Align the text in the center of the TextBox control.
   TextBox1.TextAlign = HorizontalAlignment.Center
End Sub

See Also

TextBoxBase Class | TextBoxBase Members | System.WinForms Namespace