Search code examples
c#winformstextboxmultiline

C# need to use enter key in multiline texbox to move down one line, not leave the texbox


In C# I have a multiline TextBox that users enter case notes into. However, when they enter the text box and hit the Enter key, it leaves the text box and jumps to the next field like the tab button. Is there any way to override this behavior and make the return key move down a line? I don't need to disable the return key behavior on the entire form, only in the one multiline text box.


Solution

  • You need to set the property

     textBox.AcceptsReturn = true;
    

    Without this property you could use CTRL+ENTER to initiate a newline.
    Sometimes this is useful if you need to have a default AcceptButton also set on the form.

    See MSDN documentation