TextBoxBase.Lines Propiedad

Definición

Obtiene o establece las líneas de texto de un control de cuadro de texto.

public:
 property cli::array <System::String ^> ^ Lines { cli::array <System::String ^> ^ get(); void set(cli::array <System::String ^> ^ value); };
public string[] Lines { get; set; }
member this.Lines : string[] with get, set
Public Property Lines As String()

Valor de propiedad

String[]

Matriz de cadenas que contiene el texto en un control de cuadro de texto.

Ejemplos

En el ejemplo de código siguiente se usa TextBox, una clase derivada, para extraer todas las cadenas de texto de un control de cuadro de texto de varias líneas y mostrarlas mediante el Debug.WriteLine método . En este ejemplo se requiere que se haya creado un TextBox control, denominado textBox1y que se haya rellenado con líneas de texto.

public:
   void ViewMyTextBoxContents()
   {
      #if defined(DEBUG)
      // Create a string array and store the contents of the Lines property.
      array<String^>^ tempArray = gcnew array<String^>( textBox1->Lines->Length );
      tempArray = textBox1->Lines;
      
      // Loop through the array and send the contents of the array to debug window.
      for ( int counter = 0; counter < tempArray->Length; counter++ )
      {
         System::Diagnostics::Debug::WriteLine( tempArray[ counter ] );
      }
      #endif
   }
public void ViewMyTextBoxContents()
 {
    // Create a string array and store the contents of the Lines property.
    string[] tempArray = textBox1.Lines;
 
    // Loop through the array and send the contents of the array to debug window.
    for(int counter=0; counter < tempArray.Length;counter++)
    {
       System.Diagnostics.Debug.WriteLine(tempArray[counter]);
    }
 }
Public Sub ViewMyTextBoxContents()
    Dim counter as Integer
    'Create a string array and store the contents of the Lines property.
    Dim tempArray() as String
    tempArray = textBox1.Lines
    
    'Loop through the array and send the contents of the array to debug window.
    For counter = 0 to tempArray.GetUpperBound(0)
        System.Diagnostics.Debug.WriteLine( tempArray(counter) )
    Next
 End Sub

Comentarios

Cada elemento de la matriz se convierte en una línea de texto en el control de cuadro de texto. Si la Multiline propiedad del control de cuadro de texto se establece true en y aparece un carácter de nueva línea en el texto, el texto que sigue al carácter de nueva línea se agrega a un nuevo elemento de la matriz y se muestra en una línea independiente.

Nota:

De forma predeterminada, la colección de líneas es una copia de solo lectura de las líneas de TextBox. Para obtener una colección grabable de líneas, use código similar al siguiente: textBox1.Lines = new string[] { "abcd" };

Se aplica a

Consulte también