TextBoxBase.Lines Propriété

Définition

Obtient ou définit les lignes de texte contenues dans un contrôle zone de texte.

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

Valeur de propriété

String[]

Tableau de chaînes qui contient le texte d'un contrôle zone de texte.

Exemples

L’exemple de code suivant utilise TextBox, une classe dérivée, pour extraire toutes les chaînes de texte d’un contrôle de zone de texte multiligne et les affiche à l’aide de la Debug.WriteLine méthode . Cet exemple nécessite qu’un TextBox contrôle ait été créé, nommé textBox1, et qu’il ait été rempli de lignes de texte.

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

Remarques

Chaque élément du tableau devient une ligne de texte dans le contrôle de zone de texte. Si la Multiline propriété du contrôle de zone de texte est définie true sur et qu’un caractère de nouvelle ligne apparaît dans le texte, le texte qui suit le caractère de nouvelle ligne est ajouté à un nouvel élément dans le tableau et affiché sur une ligne distincte.

Notes

Par défaut, la collection de lignes est une copie en lecture seule des lignes dans .TextBox Pour obtenir une collection de lignes accessible en écriture, utilisez un code similaire à ce qui suit : textBox1.Lines = new string[] { "abcd" };

S’applique à

Voir aussi