Delete a specific line in a .NET RichTextBox

后端 未结 9 1623
后悔当初
后悔当初 2021-01-19 15:08

How can I delete a specific line of text in a RichTextBox ?

9条回答
  •  天命终不由人
    2021-01-19 15:42

    This also could do the trick (if you can handle things such as ++ in forms code). Keeps the text format. Just remember "ReadOnly" attribute work for both you and user.

    richTextBox.SelectionStart = richTextBox.GetFirstCharIndexFromLine(your_line);
    richTextBox.SelectionLength = this.richTextBox.Lines[your_line].Length+1;
    this.richTextBox.SelectedText = String.Empty;
    

提交回复
热议问题