Aracılığıyla paylaş


TextBoxBase.MaxLength Özellik

Tanım

Kullanıcının metin kutusu denetimine yazabileceği veya yapıştırabileceği en fazla karakter sayısını alır veya ayarlar.

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

Özellik Değeri

Denetime girilebilen karakter sayısı. Varsayılan değer 32767'dir.

Özel durumlar

özelliğine atanan değer 0'dan küçüktür.

Örnekler

Aşağıdaki kod örneği, TextBoxparola kabul etmek için kullanılan bir metin kutusu oluşturmak için türetilmiş sınıfını kullanır. Bu örnek, CharacterCasing büyük harfe yazılan tüm karakterleri değiştirmek için özelliğini ve MaxLength parola uzunluğunu sekiz karakterle kısıtlamak için özelliğini kullanır. Bu örnekte, denetimdeki TextBox parolayı TextAlign ortalamak için özelliği de kullanılır.

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

Açıklamalar

Bu özelliği, posta kodları ve telefon numaraları gibi değerler için denetime girilen metnin uzunluğunu kısıtlamak veya veriler veritabanına girilirken girilen metnin uzunluğunu kısıtlamak için kullanabilirsiniz. Denetime girilen metni veritabanındaki ilgili alanın uzunluk üst sınırıyla sınırlayabilirsiniz.

Uyarı

Kodda, özelliğinin Text değerini, özelliği tarafından belirtilen değerden daha uzun bir uzunluğa sahip bir değere MaxLength ayarlayabilirsiniz. Bu özellik yalnızca çalışma zamanında denetime girilen metni etkiler.

Şunlara uygulanır