Bagikan melalui


TextBoxBase.Lines Properti

Definisi

Mendapatkan atau mengatur baris teks dalam kontrol kotak teks.

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

Nilai Properti

String[]

Array string yang berisi teks dalam kontrol kotak teks.

Contoh

Contoh kode berikut menggunakan TextBox, kelas turunan, untuk mengekstrak semua string teks dari kontrol kotak teks multibaris dan menampilkannya menggunakan Debug.WriteLine metode . Contoh ini mengharuskan TextBox kontrol telah dibuat, bernama textBox1, dan telah diisi dengan baris teks.

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

Keterangan

Setiap elemen dalam array menjadi baris teks dalam kontrol kotak teks. Multiline Jika properti kontrol kotak teks diatur ke true dan karakter baris baru muncul dalam teks, teks setelah karakter baris baru ditambahkan ke elemen baru dalam array dan ditampilkan pada baris terpisah.

Nota

Secara default, kumpulan baris adalah salinan baris baca-saja di TextBox. Untuk mendapatkan kumpulan baris yang dapat ditulis, gunakan kode yang mirip dengan yang berikut ini: textBox1.Lines = new string[] { "abcd" };

Berlaku untuk

Lihat juga