Export (0) Print
Expand All

TextBox.AcceptsReturn Property

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.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public bool AcceptsReturn { get; set; }
/** @property */
public boolean get_AcceptsReturn ()

/** @property */
public void set_AcceptsReturn (boolean value)

public function get AcceptsReturn () : boolean

public function set AcceptsReturn (value : boolean)

Not applicable.

Property Value

true 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. The default is false.

If the value of this property is false, the user must press CTRL+ENTER to create a new line in a multiline TextBox control. 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.

Windows Mobile 2003 for Pocket PC, Windows Mobile 2003 for Smartphone, Windows CE Platform Note: Although you can set this property to false, it always operates as true. If you want the ENTER key to activate a particular button, you can derive a class from TextBox and provide event-handler code for ENTER when the KeyPress event occurs.

The following code example creates a multiline TextBox control with vertical scroll bars. 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 = 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 void CreateMyMultilineTextBox()
{
    // Create an instance of a TextBox control.
    TextBox textBox1 = new TextBox();
    // Set the Multiline property to true.
    textBox1.set_Multiline(true);
    // Add vertical scroll bars to the TextBox control.
    textBox1.set_ScrollBars(ScrollBars.Vertical);
    // Allow the RETURN key to be entered in the TextBox control.
    textBox1.set_AcceptsReturn(true);
    // Allow the TAB key to be entered in the TextBox control.
    textBox1.set_AcceptsTab(true);
    // Set WordWrap to true to allow text to wrap to the next line.
    textBox1.set_WordWrap(true);
    // Set the default text of the control.
    textBox1.set_Text("Welcome!");
} //CreateMyMultilineTextBox

public function CreateMyMultilineTextBox()
 {
    // Create an instance of a TextBox control.
    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!";
 }
 

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft