共用方式為


TextBoxBase.WordWrap 屬性

定義

表示多行文字框控制項是否會在必要時自動將單字包裹到下一行開頭。

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

屬性值

true 如果多行文字框控制了字的包裝; false 當使用者越過右邊時,文字框控制鍵會自動水平滾動。 預設值為 true

範例

以下程式碼範例使用 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

備註

如果此屬性設定為 true,無論屬性設定如何 ScrollBars ,水平捲動條都不會顯示。

備註

在導出類別中, TextBox控制項內的文字無論該屬性的屬性設定為何,都會包裹,除非該 TextAlign 屬性設為 HorizontalAlignment.Left

適用於