Freigeben über


TextBoxBase.TextLength-Eigenschaft

Ruft die Länge des Texts im Steuerelement ab.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Overridable ReadOnly Property TextLength As Integer
'Usage
Dim instance As TextBoxBase
Dim value As Integer

value = instance.TextLength
public virtual int TextLength { get; }
public:
virtual property int TextLength {
    int get ();
}
/** @property */
public int get_TextLength ()
public function get TextLength () : int

Eigenschaftenwert

Die Anzahl der im Text des Steuerelements enthaltenen Zeichen.

Hinweise

Sie können mit dieser Eigenschaft die Anzahl der Zeichen in einer Zeichenfolge für Tasks wie das Suchen bestimmter Textzeichenfolgen im Text des Steuerelements bestimmen, bei denen die Gesamtanzahl der Zeichen erforderlich ist.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie mit der AppendText-Methode und der TextLength-Eigenschaft Text aus einer TextBox in eine andere kopiert wird. In diesem Beispiel ist es erforderlich, dass zwei TextBox-Steuerelemente mit den Namen textBox1 und textBox2 einem Formular hinzugefügt wurden und dass der Text-Eigenschaft von textBox1 Text zugewiesen wurde.

Private Sub AppendTextBox1Text()
   ' Determine if text is selected in textBox1.
   If textBox1.SelectionLength = 0 Then
      ' No selection made, return.
      Return
   End If
   ' Determine if the text being appended to textBox2 exceeds the MaxLength property.
   If textBox1.SelectedText.Length + textBox2.TextLength > textBox2.MaxLength Then
      MessageBox.Show("The text to paste in is larger than the maximum number of characters allowed")
      ' Append the text from textBox1 into textBox2.
   Else
      textBox2.AppendText(textBox1.SelectedText)
   End If
End Sub
private void AppendTextBox1Text()
{
   // Determine if text is selected in textBox1.
   if(textBox1.SelectionLength == 0)
      // No selection made, return.
      return;
   
   // Determine if the text being appended to textBox2 exceeds the MaxLength property.
   if((textBox1.SelectedText.Length + textBox2.TextLength) > textBox2.MaxLength)
      MessageBox.Show("The text to paste in is larger than the maximum number of characters allowed");
   else
      // Append the text from textBox1 into textBox2.
      textBox2.AppendText(textBox1.SelectedText);
}
void AppendTextBox1Text()
{
   // Determine if text is selected in textBox1.
   if ( textBox1->SelectionLength == 0 )

   // No selection made, return.
   return;

   // Determine if the text being appended to textBox2 exceeds the MaxLength property.
   if ( (textBox1->SelectedText->Length + textBox2->TextLength) > textBox2->MaxLength )
         MessageBox::Show( "The text to paste in is larger than the maximum number of characters allowed" ); // Append the text from textBox1 into textBox2.
   else
         textBox2->AppendText( textBox1->SelectedText );
}
private void AppendTextBox1Text()
{
    // Determine if text is selected in textBox1.
    if (textBox1.get_SelectionLength() == 0) {
        // No selection made, return.
        return;
    }
    // Determine if the text being appended to textBox2 exceeds the MaxLength
    // property.
    if (textBox1.get_SelectedText().get_Length()
        + textBox2.get_TextLength() > textBox2.get_MaxLength()) {
        MessageBox.Show("The text to paste in is larger than the maximum"
            + " number of characters allowed");
    }        
    else {
        // Append the text from textBox1 into textBox2.
        textBox2.AppendText(textBox1.get_SelectedText());
    }        
} //AppendTextBox1Text

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

TextBoxBase-Klasse
TextBoxBase-Member
System.Windows.Forms-Namespace
TextBoxBase.Text-Eigenschaft