TextBoxBase.Lines Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Возвращает или задает строки текста в элементе управления "Текстовое поле".
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()
Значение свойства
Массив строк, содержащих текст в элементе управления текстовым полем.
Примеры
В следующем примере кода используется TextBoxпроизводный класс для извлечения всех строк текста из элемента управления многострочного текстового поля и их отображения с помощью Debug.WriteLine метода. В этом примере требуется, чтобы TextBox элемент управления был создан, назван textBox1и что он был заполнен строками текста.
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
Комментарии
Каждый элемент в массиве становится строкой текста в элементе управления "Текстовое поле".
Multiline Если для свойства элемента управления "Текстовое поле" задано true значение, а в тексте отображается новый символ, текст, следующий за новым символом, добавляется в новый элемент массива и отображается в отдельной строке.
Замечание
По умолчанию коллекция строк — это копия строк, доступных только для чтения.TextBox Чтобы получить записываемую коллекцию строк, используйте код, аналогичный следующему: textBox1.Lines = new string[] { "abcd" };