Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
0 out of 3 rated this helpful - Rate this topic

TextBoxBase.Lines Property

Gets or sets the lines of text in a text box control.

[Visual Basic]
Public Property Lines As String ()
[C#]
public string[] Lines {get; set;}
[C++]
public: __property String* get_Lines();
public: __property void set_Lines(String* __gc[]);
[JScript]
public function get Lines() : String[];
public function set Lines(String[]);

Property Value

An array of strings that contains the text in a text box control.

Remarks

Each element in the array becomes a line of text in the text box control. If the Multiline property of the text box control is set to true and a newline character appears in the text, the text following the newline character is added to a new element in the array and displayed on a separate line.

Example

[Visual Basic, C#, C++] The following example uses TextBox, a derived class, to extract all strings of text from a multiline text box control and displays them using the Debug.WriteLine method. This example assumes that a TextBox control has been created, named textBox1, and that it has been filled with lines of text.

[Visual Basic] 
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
 

[C#] 
public void ViewMyTextBoxContents()
 {
    // Create a string array and store the contents of the Lines property.
    string[] tempArray = new 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]);
    }
 }
 

[C++] 
public:
void ViewMyTextBoxContents()
 {
    // Create a string array and store the contents of the Lines property.
    String* tempArray[] = new 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]);
    }
 }
 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

TextBoxBase Class | TextBoxBase Members | System.Windows.Forms Namespace | Text

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.