TextBox.AcceptsReturn Property

  • Thread starter Thread starter Chuck Bowling
  • Start date Start date
C

Chuck Bowling

Am I doing something wrong or does the TextBox.AcceptsReturn property not
work as documented?

According to the help, "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."

I don't want the Enter key to create a new line in the textbox. I have the
property set to false but it makes a newline when I type in it anyway...
What's up with that?
 
Chuck Bowling said:
Am I doing something wrong or does the TextBox.AcceptsReturn property not
work as documented?

According to the help, "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."

I don't want the Enter key to create a new line in the textbox. I have the
property set to false but it makes a newline when I type in it anyway...
What's up with that?

From
http://msdn.microsoft.com/library/d...indowsformstextboxclassacceptsreturntopic.asp:

"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."

I'm guessing you have no default button on your form? :-)
 
<snip>

If you don't want the user to be able to insert a new line in a
multi-line text box, and you don't have a default button on your form,
you could do it like this:

private void textBox_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
e.Handled = e.KeyChar == 13;
}
 
C# Learner said:
http://msdn.microsoft.com/library/d...indowsformstextboxclassacceptsreturntopic.asp:

"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."

I'm guessing you have no default button on your form? :-)

Ah... I scoured MSDN but I missed this... thanks...
 
C# Learner said:
<snip>

If you don't want the user to be able to insert a new line in a
multi-line text box, and you don't have a default button on your form,
you could do it like this:

private void textBox_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
e.Handled = e.KeyChar == 13;
}

Actually what I wanted to do was implement a different behavior than the
default but I don't want to add a default button to my UserControl to do it.

I solved the problem by creating a control inherited from TextBox and
overriding ProcessCmdKey.

Thanks for your help.
 
Back
Top