I want to append the contents of two rich text boxes in a Windows Forms .Net application; say: stringText = richtextbox1.Rtf + richtextbox2.Rtf;
The stringText
should be RTF text, which should have \rtf line once, having concatenated rich text.
The Clipboard is not in scope here.
Also, I'm curious, if we can de-merge them.
Try this:
richTextBoxTarget.Select(richTextBoxTarget.TextLength, 0);
richTextBoxTarget.SelectedRtf = richTextBoxSource.Rtf;
This merges the contents of richTextBoxSource to the end of richTextBoxTarget. It automatically creates valid RTF with only one \rtf tag.
To de-merge, also use Select
and SelectedRtf
. The only requirement here is, that you need to know, at what position you want to split.
I know it's old question, but it seems to be a common one. Thus, I'm gonna add my answer to this, cause the marked answer make RTF's to concatenate, but it also gives an extra new line, every time.
This would be:
RichTextBoxSource.Select(0,RichTextBoxSource.TextLength);
RichTextBoxTarget.SelectedRtf = richTextBoxSource.SelectedRtf;
It's easy and works fine. Hope it will help somebody:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With