Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending Contents of two RichTextbox as a single RichText string

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.

like image 1000
iTSrAVIE Avatar asked Feb 14 '11 16:02

iTSrAVIE


2 Answers

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 Selectand SelectedRtf. The only requirement here is, that you need to know, at what position you want to split.

like image 95
Daniel Hilgarth Avatar answered Oct 14 '22 13:10

Daniel Hilgarth


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:)

like image 26
Paweł Poręba Avatar answered Oct 14 '22 11:10

Paweł Poręba