views:

158

answers:

3

I'm looking for a class/API that allows you to create and manipulate RichText strings (rtf format) for use with the RichTextbox -like controls.

I'm thinking of something like StringBuilder, but that also allows you to specify formatting as you append to it and also go back and edit previously appended segments, as well as doing string operations like like the equivalent to .Contains() or .IndexOf() and string comparisons. It may require a few additional classes to support the formatting features.

Any suggestions?

+3  A: 

Yes. http://www.codeproject.com/KB/miscctrl/RTFBuilder.aspx .

Brian
I'll take a look at this: it looks like it does about 85% of what I'm looking for, and that might be enough.
Joel Coehoorn
It's also Open Source.
Brian
A: 

iTextSharp is basically a PDF generation library but can also be used to create files as shown here.

Darin Dimitrov
I don't necessarily want a file: I want the results, including notation for the formatting, in a string variable.
Joel Coehoorn
Hmm, maybe I could use s stringstream or memorystring, but it's not intuitive.
Joel Coehoorn
A: 

Why not add a line and then format it? You can make a custom class that uses stringbuilder but also styles the text in the same sub (note that it will look fomatted as soon as drawn, since it will finish the sub and then draw it) I mean using selection to format it. Besides, I feel writing RTF is brain-dead having the control that can do it out-of-the-box.

Edit: just to clarify, I mean
1. Write the line
2. Select the parts used in the custom stringbuilder (not by matching, but by offset)
3. Style them. =)

Edit_2: now that I think about it, it has the wonderful possibility of having a simplified sintax. You can have a sub that takes just what you need:

WriteIt(username, "My text")
(date added automatically by your sub :)

Camilo Martin