Creating a newline in rich text box

25,306

Use the RichTextBox.Text property or the RichtTextBox.AppendText method to append a string with a newline.

myRichTextBox.Text += Environment.NewLine + "My new line.";

// Or

myRichTextBox.AppendText( Environment.NewLine + "My new line." );
Share:
25,306
JustASimpleGuy
Author by

JustASimpleGuy

Learning Coding ATM

Updated on July 03, 2020

Comments

  • JustASimpleGuy
    JustASimpleGuy almost 4 years

    I need help on creating a new line for my RichTextBox which I cant make work when using CheckBox.

    It keeps overlapping instead of creating a newline of words.

    Tried using the method of rtbdisplay.text = (display+envrionment.newline); example from my code:

    if (rbtnSmall.Checked == true)
    {
        rtbDisplay.Text = "displaytext".PadRight(20) + "size".PadRight(23) +
                          qty.ToString().PadRight(20) + StrongDummy;
    }
    
  • JustASimpleGuy
    JustASimpleGuy almost 10 years
    what if I wan to display the new line with my variable instead of "my new line" . i tried using my variable switching it with "my newline" still same problem
  • Tom Bogle
    Tom Bogle almost 5 years
    Worth noting: Even if you append Environment.NewLine, in RTF, only the \n is retained. If you look at the Text property, you will see that the \r is gone.
  • user3607601
    user3607601 over 2 years
    Recently encountered this causing issues because the length of my input string and the Environment.NewLine added together were greater than the total text length after using AppendText.