removing RichTextBox lines while keeping the colour of remaining lines in C#

前端 未结 3 1316
遥遥无期
遥遥无期 2020-12-11 23:09

Consider a RichTextBox which has 400 lines and includes a number of words and lines in diffident colours.

Is it possible to remove the first 100 lines of this text b

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-12 00:06

    Use the SelectionText property. First select the lines you want to remove, then remove them by setting SelectionText to an empty string. Like this:

       richTextBox1.SelectionStart = 0;
       richTextBox1.SelectionLength = richTextBox1.GetFirstCharIndexFromLine(200);
       richTextBox1.SelectedText = "";
    

    This preserves the formatting of all the other lines. This can cause visible flicker on the UI, you can suppress that by implementing the Begin/EndUpdate methods as shown here.

提交回复
热议问题