共用方式為


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" };

適用於

另請參閱