TextBox.AcceptsReturn 属性

定义

获取或设置一个值,该值指示在多行 TextBox 控件中按 Enter 键时,是在控件中创建一行新文本还是激活窗体的默认按钮。Gets or sets a value indicating whether pressing ENTER in a multiline TextBox control creates a new line of text in the control or activates the default button for the form.

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

属性值

如果按 Enter 键时在多行版本的控件中创建一行新文本,则为 true;如果按 Enter 键时激活窗体的默认按钮,则为 falsetrue if the ENTER key creates a new line of text in a multiline version of the control; false if the ENTER key activates the default button for the form. 默认值为 falseThe default is false.

示例

下面的代码示例创建一个具有垂直滚动条的多行 TextBox 控件。The following code example creates a multiline TextBox control with vertical scroll bars. 此示例使用 AcceptsTabAcceptsReturnWordWrap 属性,使多行文本框控件对于创建文本文档很有用。This example 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 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!";
   }
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!";
 }
 
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 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!"
End Sub

注解

如果此属性的值为 false,则用户必须按 CTRL + ENTER 在多行 TextBox 控件中创建新行。If the value of this property is false, the user must press CTRL+ENTER to create a new line in a multiline TextBox control. 如果窗体没有默认按钮,则无论此属性的值如何,ENTER 键都将始终在控件中创建新的文本行。If there is no default button for the form, the ENTER key will always create a new line of text in the control, regardless of the value of this property.

适用于