TextBoxBase.Lines Właściwość

Definicja

Pobiera lub ustawia wiersze tekstu w kontrolce pola tekstowego.

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()

Wartość właściwości

String[]

Tablica ciągów, która zawiera tekst w kontrolce pola tekstowego.

Przykłady

Poniższy przykład kodu używa TextBoxklasy pochodnej , aby wyodrębnić wszystkie ciągi tekstu z kontrolki pola tekstowego wielowierszowego i wyświetla je przy użyciu Debug.WriteLine metody . W tym przykładzie jest wymagane utworzenie TextBox kontrolki o nazwie textBox1i wypełnienie jej wierszami tekstu.

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

Uwagi

Każdy element w tablicy staje się wierszem tekstu w kontrolce pola tekstowego. Multiline Jeśli właściwość kontrolki pola tekstowego jest ustawiona na true , a nowy znak wiersza pojawi się w tekście, tekst po znaku nowego wiersza zostanie dodany do nowego elementu w tablicy i wyświetlany w osobnym wierszu.

Uwaga

Domyślnie kolekcja wierszy jest kopią wierszy tylko do odczytu w pliku TextBox. Aby uzyskać zapisywalną kolekcję wierszy, użyj kodu podobnego do następującego: textBox1.Lines = new string[] { "abcd" };

Dotyczy

Zobacz też