Partager via


TextBoxBase.Lines Propriété

Définition

Obtient ou définit les lignes de texte dans un contrôle de 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 de 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 afficher à l’aide de la Debug.WriteLine méthode. Cet exemple nécessite qu’un TextBox contrôle ait été créé, nommé textBox1et qu’il a é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 zone de texte. Si la Multiline propriété du contrôle zone de texte est définie true sur et qu’un caractère de ligne s’affiche dans le texte, le texte suivant le caractère de nouvelle ligne est ajouté à un nouvel élément du tableau et affiché sur une ligne distincte.

Note

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

S’applique à

Voir aussi