views:

160

answers:

3

I need to add strings coming from different RichTextBoxes with different fonts into one RichTextBox retaining the original fonts (more typically sometime I get XML format where fonts for substrings is defined.)

Is there a way of constructing this string in memory and then simply puting it in a RichTextBox? If not, is there any other way?

+2  A: 

Hi, try this

richTextBox1.SelectionStart = 0;
richTextBox1.SelectionLength = 10;
richTextBox1.SelectionFont = new Font( "Veradana", 8.25F );

foreach block with different font just repeat the code Best Reagrds, Iordan

IordanTanev
+1 for the clear example.
Dykam
I have a lot of rih textboxes like this one...
A: 

This answer gives a code sample for drawing text with different colors into a picture box. You could easily modify it to draw the text with different fonts as well. If you need the scrollability of the RichTextBox, you could place the picture box on a panel.

Update: since you need to use a RichTextBox, this link shows you how to transform your original XML into RTF that you can load into your RichTextBox. In order to do this, you have to create an XSLT document that describes how to transform the XML into RTF. The link I included gives a sample XSLT document; you would have to modify this XSLT based upon how the different fonts are specified in your original XML document (if you post a sample of your original XML, we could probably help you modify the XSLT accordingly).

MusiGenesis
This needs to be a rictextbox as text content is editable
A: 

You can save anything in RichTextBox in .rtf format using its

SaveFile
method within
RichTextBoxStreamType.RichText
format and If you wish to load saved format , call
LoadFile
method
Source here

Myra