Drawing rich text manually

G

Guest

I have a custom control that displays thousands of items. Each item is NOT a System.Windows.Control; each item is instead a simple light weight class with properties (such as .Text, .ImageIndex, etc.) used by the custom control to draw each item (i.e. the custom control draws all the items)

Here's my problem: I would like each item to display rich text. While we could write a custom RTF parser, that is a huge undertaking we'd not like to start. We cannot use the RichTextBox provided with the FCL since it is a standard System.Windows.Control which is not at all lightweight (thousands of items == thousands of RichTextBoxes, translates to bad performance plus lots of limitations related to standard WinForm Controls)

So I guess I'm looking for a way to display items containing Rich Text, thousands of items, all on a single GDI+ surface, without utilizing thousands of RichTextBox controls. Any suggestions?
 
M

Michael Mayer [C# MVP]

My first question is how do you propose to fit thousands of Rich Text
Controls on a single GDI+ surface? My monitor isn't that big.... Although if
each control may only store a few letters or controls, then that might work.

My first instinct would be to store the rich text in some light weight
class, but then instantiate the required RichTextBox
controls as necessary to actually display the text. (That is, if you are
looking at a few dozen at a time).

You could also grab a bitmap image of the rich text. Following are links
for doing it on a datagrid control - a rich text box should also work. I
would think that with this method, you could use one RichTextControl to
repeately paint text to various positions on your GDI+ Graphics object.
http://msdn.microsoft.com/library/d...con/html/vclrfcodeprintingdatagridvisualc.asp
http://www.mag37.com/projects/Printing/Releases/PrintDataGrid_Simple.zip

As for other shortcuts, you can build a parser based on a single rich text
box, using code something like shown here:
http://www.c-sharpcorner.com/Code/2003/June/ColorSyntaxEditor.asp

I've also tried my own to draw rich text to a GDI+ surface, but it is a bit
of an undertaking. Feel free to use my code as a starting point (it's not
very optimized nor debugged). You'll have to go to "Download from Releases"
then in the zip file there is a SectionRichText.cs and SectionRichText1.cs.
I don't remember what I was doing or where I left off when I pretty much
lost interest... but it shows a way to convert rich text to a gdi surface.
http://www.mag37.com/projects/Printing/index.html?tabid=10

Those are just some ideas to get you thinking. Let me know if any of these
pan out, or if you find some other solution. I'd love to be able to roll
rich text printing into the library I was/am working on.

--
Mike Mayer, C# MVP
(e-mail address removed)
http://www.mag37.com/csharp/


Gabriel said:
I have a custom control that displays thousands of items. Each item is NOT
a System.Windows.Control; each item is instead a simple light weight class
with properties (such as .Text, .ImageIndex, etc.) used by the custom
control to draw each item (i.e. the custom control draws all the items).
Here's my problem: I would like each item to display rich text. While we
could write a custom RTF parser, that is a huge undertaking we'd not like to
start. We cannot use the RichTextBox provided with the FCL since it is a
standard System.Windows.Control which is not at all lightweight (thousands
of items == thousands of RichTextBoxes, translates to bad performance plus
lots of limitations related to standard WinForm Controls).
So I guess I'm looking for a way to display items containing Rich Text,
thousands of items, all on a single GDI+ surface, without utilizing
thousands of RichTextBox controls. Any suggestions?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top