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 控制項。 此範例也會使用 AcceptsTabAcceptsReturnWordWrap 屬性,讓多行文字方塊控制項適用于建立文字檔。

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 。 這可讓使用者捲動超出控制項維度的文字。

注意

由於 屬性的 Multiline 預設值為 false ,因此即使調整 TextBox 大小,的預設大小 TextBox 仍會根據字型大小。 若要取得的 TextBox 一致大小,請將其 Multiline 屬性設定為 true

注意

在日文作業系統上,如果 Multiline 屬性設定 true 為 ,則設定 PasswordChar 屬性會顯示密碼的文字,因而危害系統安全性。 因此,在日文作業系統上,如果您設定 屬性,請將 Multiline 屬性設定為 falsePasswordChar

注意

此屬性預設會針對所有衍生類別設定為 false ,但控制項除外 RichTextBox

RichTextBox對於控制項, RichTextBox.Multiline 屬性會影響控制項是否會自動調整大小,如下所示:

適用於

另請參閱