TextBoxBase.Lines Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém ou define as linhas de texto num controlo 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 de Propriedade
Um array de strings que contém o texto num controlo de caixa de texto.
Exemplos
O seguinte exemplo de código usa TextBox, uma classe derivada, para extrair todas as cadeias de texto de um controlo de caixa de texto multilinha e exibi-las usando o Debug.WriteLine método. Este exemplo exige que um TextBox controlo tenha sido criado, nomeado textBox1, e que 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
Observações
Cada elemento do array torna-se uma linha de texto no controlo da caixa de texto. Se a Multiline propriedade do controlo da caixa de texto for definida para true e aparecer um carácter de nova linha no texto, o texto após o carácter de nova linha é adicionado a um novo elemento do array e exibido numa linha separada.
Note
Por defeito, a coleção de linhas é uma cópia apenas de leitura das linhas no TextBox. Para obter uma coleção gravável de linhas, use código semelhante ao seguinte: textBox1.Lines = new string[] { "abcd" };