TextBoxBase.WordWrap TextBoxBase.WordWrap TextBoxBase.WordWrap TextBoxBase.WordWrap Property

定义

指示多行文本框控件在必要时是否自动换行到下一行的开始。Indicates whether a multiline text box control automatically wraps words to the beginning of the next line when necessary.

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;如果当用户键入的内容超过了控件的右边缘时,文本框控件自动水平滚动,则为 falsetrue if the multiline text box control wraps words; false if the text box control automatically scrolls horizontally when the user types past the right edge of the control. 默认值为 trueThe default is true.

示例

下面的代码示例使用TextBox派生类创建具有垂直滚动条的多TextBox行控件。The following code example uses TextBox, a derived class, to create a multiline TextBox control with vertical scroll bars. 此示例还使用AcceptsTabAcceptsReturnWordWrap属性使 "多行文本框" 控件对创建文本文档有用。This example also uses the AcceptsTab, AcceptsReturn, and WordWrap properties to make the multiline text box control useful for creating text documents.

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属性设置如何,都不会显示水平滚动条。If this property is set to true, horizontal scroll bars are not displayed regardless of the ScrollBars property setting.

备注

在派生类TextBox中, TextAlign如果属性设置为HorizontalAlignment.Left,则控件中的文本将始终换行,而与此属性的属性设置无关。In the derived class, TextBox, text within the control will always wrap regardless of the property setting of this property unless the TextAlign property is set to HorizontalAlignment.Left.

适用于