How to remove line from richTextBox

  • I want to remove specific lines from richTextBox(it update every 2 minutes) without losing format e.i, I found this piece of code on stackOverflow it work but still losing format

    richTextBox1.SelectionStart = richTextBox1.GetFirstCharIndexFromLine(my Line);
    richTextBox1.SelectionLength = this.richTextBox1.Lines[my Line].Length + 1;
    this.richTextBox1.SelectedText = String.Empty;

  • Admin

    Isn't it better to just get the whole text, divide it into lines, remove the unnecessary ones, join it back into a single string and set the text again? Do you really need to do this by exploiting the cursor and the selection?

  • @Ruri thanks

Log in to reply