Language

TextBoxBase.Multiline プロパティ

定義

複数行テキスト ボックス コントロールかどうかを示す値を取得または設定します。

public:
 virtual property bool Multiline { bool get(); void set(bool value); };
public virtual bool Multiline { get; set; }
member this.Multiline : bool with get, set
Public Overridable Property Multiline As Boolean

プロパティ値

true コントロールが複数行テキスト ボックス コントロールの場合。それ以外の場合は false。 既定値は false です。

例

次のコード例では、派生クラス TextBoxを使用して、垂直スクロール バーを含む複数行 TextBox コントロールを作成します。 この例では、 AcceptsTab、 AcceptsReturn、および WordWrap プロパティを使用して、テキスト ドキュメントの作成に役立つ複数行テキスト ボックス コントロールを作成します。

public:
   void CreateMyMultilineTextBox()
   {
      // Create an instance of a TextBox control.
      TextBox^ textBox1 = gcnew TextBox;
      
      // Set the Multiline property to true.
      textBox1->Multiline = true;
      // Add vertical scroll bars to the TextBox control.
      textBox1->ScrollBars = ScrollBars::Vertical;
      // Allow the RETURN key in the TextBox control.
      textBox1->AcceptsReturn = true;
      // Allow the TAB key to be entered in the TextBox control.
      textBox1->AcceptsTab = true;
      // Set WordWrap to true to allow text to wrap to the next line.
      textBox1->WordWrap = true;
      // Set the default text of the control.
      textBox1->Text = "Welcome!" + Environment::NewLine + "Second Line";
   }
public void CreateMyMultilineTextBox()
 {
    // Create an instance of a TextBox control.
    TextBox textBox1 = new TextBox();
    
    // Set the Multiline property to true.
    textBox1.Multiline = true;
    // Add vertical scroll bars to the TextBox control.
    textBox1.ScrollBars = ScrollBars.Vertical;
    // Allow the RETURN key in the TextBox control.
    textBox1.AcceptsReturn = true;
    // Allow the TAB key to be entered in the TextBox control.
    textBox1.AcceptsTab = true;
    // Set WordWrap to true to allow text to wrap to the next line.
    textBox1.WordWrap = true;
    // Set the default text of the control.
    textBox1.Text = "Welcome!" + Environment.NewLine + "Second Line";
 }
Public Sub CreateMyMultilineTextBox()
    ' Create an instance of a TextBox control.
    Dim textBox1 As New TextBox()
    
    ' Set the Multiline property to true.
    textBox1.Multiline = True
    ' Add vertical scroll bars to the TextBox control.
    textBox1.ScrollBars = ScrollBars.Vertical
    ' Allow the RETURN key in the TextBox control.
    textBox1.AcceptsReturn = True
    ' Allow the TAB key to be entered in the TextBox control.
    textBox1.AcceptsTab = True
    ' Set WordWrap to true to allow text to wrap to the next line.
    textBox1.WordWrap = True
    ' Set the default text of the control.
    textBox1.Text = "Welcome!" & Environment.NewLine & "Second Line"
End Sub

注釈

複数行のテキスト ボックスを使用すると、コントロールに複数行のテキストを表示できます。 WordWrap プロパティが true に設定されている場合、複数行テキスト ボックスに入力されたテキストは、コントロール内の次の行に折り返されます。 WordWrap プロパティが false に設定されている場合、複数行テキスト ボックス コントロールに入力されたテキストは、改行文字が入力されるまで同じ行に表示されます。

改行文字として使用できる文字は次のとおりです。

ScrollBars プロパティを使用してテキスト ボックスにスクロール バーを追加すると、水平スクロール バーや垂直スクロール バーを表示できます。 これにより、ユーザーはコントロールの寸法を超えるテキストをスクロールできます。

Note

Multiline プロパティの既定値はfalseされるため、TextBoxの既定のサイズは、TextBoxのサイズを変更した場合でもフォント サイズに従います。 TextBoxの一貫したサイズを取得するには、そのMultilineプロパティをtrueに設定します。

Note

日本語のオペレーティング システムでは、 Multiline プロパティが true に設定されている場合、 PasswordChar プロパティを設定するとパスワードのテキストが表示されるため、システムのセキュリティが損なわれます。 したがって、日本語のオペレーティング システムでは、Multiline プロパティを設定する場合は、false プロパティをPasswordCharに設定します。

Note

このプロパティは、false コントロールを除き、すべての派生クラスに対して既定でRichTextBoxに設定されます。

RichTextBox コントロールの場合、RichTextBox.Multiline プロパティは、コントロールのサイズを自動的に変更するかどうかに影響します。次に示します。

適用対象

こちらもご覧ください