TextBoxBase.Lines Propriedade

Definição

Obtém ou define as linhas de texto em um controle de caixa 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 da propriedade

String[]

Uma matriz de cadeias de caracteres que contém o texto em um controle de caixa de texto.

Exemplos

O exemplo de código a seguir usa TextBox, uma classe derivada, para extrair todas as cadeias de texto de um controle de caixa de texto de várias linhas e exibe-as usando o Debug.WriteLine método. Este exemplo requer que um TextBox controle tenha sido criado, nomeado textBox1e que ele tenha sido preenchido com linhas 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

Comentários

Cada elemento na matriz se torna uma linha de texto no controle da caixa de texto. Se a Multiline propriedade do controle da caixa de texto estiver definida true e um caractere newline for exibido no texto, o texto a seguir será adicionado a um novo elemento na matriz e exibido em uma linha separada.

Observação

Por padrão, a coleção de linhas é uma cópia somente leitura das linhas na TextBox. Para obter uma coleção gravável de linhas, use um código semelhante ao seguinte: textBox1.Lines = new string[] { "abcd" };

Aplica-se a

Confira também