TextBoxBase.MaxLength Eigenschap

Definitie

Hiermee haalt of stelt u het maximum aantal tekens in dat de gebruiker in het tekstvak besturingselement kan typen of plakken.

public:
 virtual property int MaxLength { int get(); void set(int value); };
public virtual int MaxLength { get; set; }
member this.MaxLength : int with get, set
Public Overridable Property MaxLength As Integer

Waarde van eigenschap

Het aantal tekens dat in het besturingselement kan worden ingevoerd. De standaardwaarde is 32767.

Uitzonderingen

De waarde die aan de eigenschap is toegewezen, is kleiner dan 0.

Voorbeelden

In het volgende codevoorbeeld wordt de afgeleide klasse TextBoxgebruikt om een tekstvak te maken dat wordt gebruikt om een wachtwoord te accepteren. In dit voorbeeld wordt de CharacterCasing eigenschap gebruikt om alle tekens te wijzigen die zijn getypt in hoofdletters en de MaxLength eigenschap om de wachtwoordlengte te beperken tot acht tekens. In dit voorbeeld wordt ook de TextAlign eigenschap gebruikt om het wachtwoord in het TextBox besturingselement te centreren.

public:
   void CreateMyPasswordTextBox()
   {
      // Create an instance of the TextBox control.
      TextBox^ textBox1 = gcnew TextBox;
      // Set the maximum length of text in the control to eight.
      textBox1->MaxLength = 8;
      // Assign the asterisk to be the password character.
      textBox1->PasswordChar = '*';
      // Change all text entered to be uppercase.
      textBox1->CharacterCasing = CharacterCasing::Upper;
      // Align the text in the center of the TextBox control.
      textBox1->TextAlign = HorizontalAlignment::Center;
   }
public void CreateMyPasswordTextBox()
 {
    // Create an instance of the TextBox control.
    TextBox textBox1 = new TextBox();
    // Set the maximum length of text in the control to eight.
    textBox1.MaxLength = 8;
    // Assign the asterisk to be the password character.
    textBox1.PasswordChar = '*';
    // Change all text entered to be uppercase.
    textBox1.CharacterCasing = CharacterCasing.Upper;
    // Align the text in the center of the TextBox control.
    textBox1.TextAlign = HorizontalAlignment.Center;
 }
Public Sub CreateMyPasswordTextBox()
    ' Create an instance of the TextBox control.
    Dim textBox1 As New TextBox()
    ' Set the maximum length of text in the control to eight.
    textBox1.MaxLength = 8
    ' Assign the asterisk to be the password character.
    textBox1.PasswordChar = "*"c
    ' Change all text entered to be uppercase.
    textBox1.CharacterCasing = CharacterCasing.Upper
    ' Align the text in the center of the TextBox control.
    textBox1.TextAlign = HorizontalAlignment.Center
End Sub

Opmerkingen

U kunt deze eigenschap gebruiken om de lengte van de tekst die in het besturingselement is ingevoerd, te beperken voor waarden zoals postcodes en telefoonnummers, of om de lengte van de ingevoerde tekst te beperken wanneer de gegevens in een database moeten worden ingevoerd. U kunt de tekst die in het besturingselement is ingevoerd, beperken tot de maximale lengte van het bijbehorende veld in de database.

Note

In code kunt u de waarde van de Text eigenschap instellen op een waarde met een lengte die groter is dan de waarde die is opgegeven door de MaxLength eigenschap. Deze eigenschap is alleen van invloed op tekst die tijdens runtime in het besturingselement is ingevoerd.

Van toepassing op