locked
Adding Text To A Rich Text Box ... RRS feed

  • Question

  • I am in need of help in adding certain text to a ri ch text box.

    I am need to add something like this:

    Dim a As Integer

    RichTextBox1.Text = a "@email.com"


    But, I need to make it add a new entry to a different line. I need to add onto the text, and not replace it.

    So when it comes out, it looks like:

    1@email.com
    2@email.com
    etc

    I already have a method for starting and stopping this.

    Feel free to ask any questions.

    Resentful
    Monday, May 4, 2009 3:09 AM

Answers

  • Use " vbCrLf " concatenated to the end of your string to start a new line of text.

            Dim i As Integer = 1   'This, presumably will change in a loop??
            Dim myStr = i.ToString & "@email.com" & vbCrLf   'Build the string for the RichTextBox (RTB)
            RTB.AppendText = myStr   'Write the string into the RTB

    Each time you add text to the RichTextBox, it will begin on a new line.


    Doug
    • Marked as answer by Resentful Monday, May 4, 2009 3:21 AM
    • Edited by _-Steve-_ Monday, May 4, 2009 3:24 AM
    Monday, May 4, 2009 3:13 AM
  • Hi,

    Use RichTextBox1.AppendText instead of using .Text for the second time.

    It should solve your problem!!

    Thanks.
    • Marked as answer by Resentful Monday, May 4, 2009 3:21 AM
    Monday, May 4, 2009 3:15 AM

All replies

  • Use " vbCrLf " concatenated to the end of your string to start a new line of text.

            Dim i As Integer = 1   'This, presumably will change in a loop??
            Dim myStr = i.ToString & "@email.com" & vbCrLf   'Build the string for the RichTextBox (RTB)
            RTB.AppendText = myStr   'Write the string into the RTB

    Each time you add text to the RichTextBox, it will begin on a new line.


    Doug
    • Marked as answer by Resentful Monday, May 4, 2009 3:21 AM
    • Edited by _-Steve-_ Monday, May 4, 2009 3:24 AM
    Monday, May 4, 2009 3:13 AM
  • Hi,

    Use RichTextBox1.AppendText instead of using .Text for the second time.

    It should solve your problem!!

    Thanks.
    • Marked as answer by Resentful Monday, May 4, 2009 3:21 AM
    Monday, May 4, 2009 3:15 AM
  • Hmm, it did not start on a new line, but only replaced the text.

    I need it to make a list.
    Monday, May 4, 2009 3:17 AM
  • Hi,

    .Text will replace the existing text and .AppendText will append the new text to the existing text. So, in your case you have to use .AppendText.
    • Marked as answer by Resentful Monday, May 4, 2009 3:21 AM
    • Unmarked as answer by Resentful Monday, May 4, 2009 3:21 AM
    Monday, May 4, 2009 3:17 AM
  • Thanks everyone.
    Monday, May 4, 2009 3:21 AM
  • That's correct.  When looping and writing text into a RichTextBox, the text currently in it will be replaced.  Use the .AppendText routine to get the results you want.  My mistake.
    Doug
    Monday, May 4, 2009 3:24 AM