TextBoxBase.Lines Egenskap

Definition

Hämtar eller anger textraderna i en textrutekontroll.

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

Egenskapsvärde

String[]

En matris med strängar som innehåller texten i en textrutekontroll.

Exempel

I följande kodexempel används TextBox, en härledd klass, för att extrahera alla textsträngar från en textrutekontroll med flera rader och visa dem med hjälp av Debug.WriteLine metoden . Det här exemplet kräver att en TextBox kontroll har skapats, med namnet textBox1, och att den har fyllts med textrader.

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

Kommentarer

Varje element i matrisen blir en textrad i textrutekontrollen. Multiline Om egenskapen för textrutekontrollen är inställd på true och ett nytt radtecken visas i texten läggs texten efter det nya radtecknet till i ett nytt element i matrisen och visas på en separat rad.

Note

Som standard är samlingen med rader en skrivskyddad kopia av raderna i TextBox. Om du vill hämta en skrivbar samling rader använder du kod som liknar följande: textBox1.Lines = new string[] { "abcd" };

Gäller för

Se även