TextBox.Multiline 屬性

定義

取得或設定值,其會表示這是否為多行 TextBox 控制項。

C#
public override bool Multiline { get; set; }

屬性值

如果控制項是多行 TextBox 控制項,則為 true,否則為 false。 預設為 false

範例

下列程式碼範例會建立具有垂直捲動條的多行 TextBox 控制項。 這個範例會使用 AcceptsTabAcceptsReturnWordWrap 屬性,讓多行文字方塊控制項適用于建立文字檔。

C#
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 to be entered 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!";
 }

備註

AutoCompleteSource 無法在多行 TextBox 控制項上運作。

變更字型時,您定義的任何縮排都不會出現。 若要取得縮排,請將 設定 Multilinetrue 並覆寫WM_SETFONT而不呼叫基類,因此不會呼叫 SETMARGINS。

適用於

產品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10