문제

I have formatted text in the rtf file and I load it to my richTextBox. It works fine, but then I want to remove some text parts programmatically. If I do like that:

richTextBox.LoadFile("TextFile.rtf");
richTextBox.Text = richTextBox1.Text.Substring(fromPosition, length);

text formatting disappears. I've tried to work with richTextBox.Lines, but there is no delete or edit function. All I need is to delete parts of loaded text without losing its formatting. Is it possible?

Thanks in advance.

도움이 되었습니까?

해결책

To remove text you first select it, programmatically by setting SelectionStart and -Length. Then you use the Cut Method:

    richTextBox1.SelectionStart = 20;
    richTextBox1.SelectionLength = 120;
    richTextBox1.Cut();

If you want to avoid putting the removed text to the clipboard you can set it to "" instead of 'cutting' it:

    richTextBox1.SelectedText = ""
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top