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

屬性值

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,以在多行控制項中建立新的行 TextBoxIf 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.

適用於