Condividi tramite


TextBoxBase.Lines Proprietà

Definizione

Ottiene o imposta le righe di testo in un controllo casella di testo.

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

Valore della proprietà

String[]

Matrice di stringhe che contiene il testo in un controllo casella di testo.

Esempio

Nell'esempio di codice seguente viene TextBoxutilizzato , una classe derivata, per estrarre tutte le stringhe di testo da un controllo casella di testo su più righe e visualizzarle usando il Debug.WriteLine metodo . In questo esempio è necessario che sia stato creato un TextBox controllo denominato textBox1e che sia stato riempito con righe di testo.

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

Commenti

Ogni elemento della matrice diventa una riga di testo nel controllo casella di testo. Se la Multiline proprietà del controllo casella di testo è impostata su true e nel testo viene visualizzato un carattere di nuova riga, il testo che segue il carattere di nuova riga viene aggiunto a un nuovo elemento nella matrice e visualizzato su una riga separata.

Annotazioni

Per impostazione predefinita, l'insieme di righe è una copia di sola lettura delle righe in TextBox. Per ottenere una raccolta scrivibile di righe, usare codice simile al seguente: textBox1.Lines = new string[] { "abcd" };

Si applica a

Vedi anche