Q
Problem solve Get help with specific problems with your technologies, process and projects.

How do I write multiple text lines to a rich text box?

How do I write multiple text lines to a rich text box, such as:

Line 1 xxxxxx Line 2 yyyyyy Line 3 mmmmmm and so on?

Also, I notice that the rich text box has a +Lines: String[]Array. Can this be used to write text from variables?
Here are two button handlers that show both ways and produce the same text in the RichTextBox control:
  Private Sub Button1_Click(ByVal sender As System.Object, _
                ByVal e As System.EventArgs) _
                Handles Button1.Click
    RichTextBox1.Text = "Line 1 xxxxxx" + vbCrLf
    RichTextBox1.Text += "Line 2 yyyyyy" + vbCrLf
    RichTextBox1.Text += "Line 3 mmmmmm and so on?" + vbCrLf
  End Sub

  Private Sub Button2_Click(ByVal sender As System.Object, _
                ByVal e As System.EventArgs) _
                Handles Button2.Click
    Dim myLines(3) As String

    myLines(0) = "[using Lines] Line 1 xxxxxx"
    myLines(1) = "[using Lines] Line 2 yyyyyy"
    myLines(2) = "[using Lines] Line 3 mmmmmm and so on?"

    RichTextBox1.Lines = myLines
  End Sub

This was last published in June 2004

Dig Deeper on VB code downloads

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

TheServerSide.com

SearchCloudApplications

Close