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 ha
The richtextbox also has a "Lines" property that is an array of strings. Each item in this array ends in an implicit line break and will be displayed on its own line.
If your text is static or has an initial value and you are using the designer in Visual Studio you can simply add lines directly there.
Try vbCrLf
.
For example:
TextBox1.text = "line_one" & vbCrLf & "line_two"
TextBox2.Text = "Line 1" & Environment.NewLine & "Line 2"
or
TextBox2.Text = "Line 1"
TextBox2.Text += Environment.NewLine
TextBox2.Text += "Line 2"
This, is how it is done.
Took this from JeffK and made it a little more compact.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Newline As String = System.Environment.NewLine
TextBox1.Text = "This is a test"
TextBox1.Text += Newline + "This is another test"
End Sub
Try something like
"Line 1" & Environment.NewLine & "Line 2"
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)