Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a newline to a windows-forms TextBox?

I am trying to add a line of text to a TextBox component in VB.net, but I cannot figure out for the life of me how to force a new line. Right now it just adds onto what I have already, and that is not good.

I have tried copying the actual linebreaks, didn't work. I tried AppendText(), didn't work.

How on earth do I do this? It is multiline already.

like image 770
Cyclone Avatar asked Aug 19 '09 21:08

Cyclone


People also ask

How do I insert a line break in a text box?

Of course, there are situations in which there is need to add line breaks. You can do so by simply hitting Shift + Return or Shift + Enter , respectively.

How do you enable more than one line in a Windows Forms text box?

Step 1: Create a windows form. Step 2: Drag the TextBox control from the ToolBox and drop it on the windows form. You can place TextBox anywhere on the windows form according to your need. Step 3: After drag and drop you will go to the properties of the TextBox control to set the Multiline property of the TextBox.


2 Answers

Try using Environment.NewLine:

Gets the newline string defined for this environment.

Something like this ought to work:

textBox.AppendText("your new text" & Environment.NewLine) 
like image 85
Andrew Hare Avatar answered Sep 22 '22 08:09

Andrew Hare


Try something like

"Line 1" & Environment.NewLine & "Line 2" 
like image 22
JohannesH Avatar answered Sep 19 '22 08:09

JohannesH