TextBoxBase.Lines Eigenschap

Definitie

Hiermee haalt u de tekstregels op of stelt u deze in een tekstvak besturingselement in.

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

Waarde van eigenschap

String[]

Een matrix met tekenreeksen die de tekst in een tekstvak-besturingselement bevat.

Voorbeelden

In het volgende codevoorbeeld wordt een afgeleide klasse gebruikt TextBoxom alle tekenreeksen met tekst uit een besturingselement met meerdere regels te extraheren en weer te geven met behulp van de Debug.WriteLine methode. In dit voorbeeld is vereist dat een TextBox besturingselement is gemaakt, benoemd textBox1en dat het is gevuld met regels tekst.

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

Opmerkingen

Elk element in de matrix wordt een tekstregel in het tekstvak besturingselement. Als de Multiline eigenschap van het tekstvakbesturingselement is ingesteld true op en er een nieuw regelteken wordt weergegeven in de tekst, wordt de tekst na het nieuwe regelteken toegevoegd aan een nieuw element in de matrix en weergegeven op een afzonderlijke regel.

Note

Standaard is de verzameling regels een alleen-lezen kopie van de regels in de TextBox. Als u een schrijfbare verzameling regels wilt ophalen, gebruikt u code die vergelijkbaar is met de volgende: textBox1.Lines = new string[] { "abcd" };

Van toepassing op

Zie ook