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.
[Visual Basic] Public Property AcceptsReturn As Boolean [C#] public bool AcceptsReturn {get; set;} [C++] public: __property bool get_AcceptsReturn(); public: __property void set_AcceptsReturn(bool); [JScript] public function get AcceptsReturn() : Boolean; public function set AcceptsReturn(Boolean);
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.
Remarks
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, then the ENTER key will always create a new line of text in the control, no matter what the value of this property.
.NET Compact Framework Platform Note: Although you can set AcceptsReturn 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 handling code for ENTER when the KeyPress event occurs.
Example
The following 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.
[Visual Basic] 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 [C#] 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!"; } [C++] 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 = S"Welcome!"; } [JScript] 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!"; }
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
See Also
TextBox Class | TextBox Members | System.Windows.Forms Namespace