views:

754

answers:

6

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.

Thanks for the help!

+7  A: 

Try using Environment.NewLine:

Gets the newline string defined for this environment.

Something like this ought to work:

textBox.AppendText(Environment.NewLine & "your new text")
Andrew Hare
It worked, thanks!
Cyclone
+2  A: 

Try something like

"Line 1" & Environment.NewLine & "Line 2"
JohannesH
A: 

Have you tried something like:

textbox.text = "text" & system.environment.newline & "some more text"

klabranche
A: 

Have you set AcceptsReturn property to true?

shahkalpesh
That's for accepting the enter keypress.
Guffa
Thanks Guffa. You are right.
shahkalpesh
A: 

First you have to set the MultiLine property of the TextBox to true so that it supports multiple lines.

Then you just use Environment.NewLine to get the newline character combination.

Guffa
A: 

Quickie test code for WinForms in VB:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim Newline As String
    Newline = System.Environment.NewLine

    TextBox1.Text = "This is a test"
    TextBox1.Text = TextBox1.Text & Newline & "This is line 2"

End Sub
JeffK