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 使用して表示します。 この例では、コントロールが作成され、名前が付textBox1けられ、テキスト行が入力されている必要TextBoxがあります。

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

適用対象

こちらもご覧ください