2

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?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794

3 Answers3

2

Try this:

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

foreach block with different font just repeat the code

IordanTanev
  • 6,130
  • 5
  • 40
  • 49
0

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

Community
  • 1
  • 1
MusiGenesis
  • 74,184
  • 40
  • 190
  • 334
0

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
  • 3,646
  • 3
  • 38
  • 47