TextBoxBase.Lines 屬性

定義

取得或設定文字方塊控制項中的文字行數。

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

屬性值

String[]

字串陣列,包含文字方塊控制項中的文字。

範例

下列程式碼範例會使用 TextBox 衍生類別,從多行文字方塊控制項擷取所有文字字串,並使用 方法加以顯示 Debug.WriteLine 。 此範例會要求 TextBox 已建立名為 的 textBox1 控制項,而且已填入文字行。

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

備註

陣列中的每個元素都會成為文字方塊控制項中的一行文字。 Multiline如果文字方塊控制項的 屬性設定 true 為 ,且文字中會出現分行符號,則分行符號後面的文字會新增至陣列中的新元素,並顯示在個別行上。

注意

根據預設,行集合是 中 TextBox 行的唯讀複本。 若要取得行的可寫入集合,請使用類似下列的程式碼: textBox1.Lines = new string[] { "abcd" };

適用於

另請參閱