views:

238

answers:

2

I'm trying to create a rich text DataGridViewCell. I can host a RichTextBox as the editing control, but when the cell isn't in editing mode I need to paint the rich text myself. I don't want to parse the text - I just need an equivalent of Graphics.DrawString that works with rich text.

A: 

I don't believe there's a solution within WinForms that can do that for you. The best approach here is probably to use the RichTextBox for both plain rendering and editing, and just lock it (set Locked to true) when not in edit mode.

Noldorin
The editing control of a DataGridViewCell isn't displayed when the cell isn't in edit mode - I need to be able to render the text even when I don't have access to an onscreen RichTextBox instance.
Simon
print to a custom graphics device context built upon an image. That's a native part of winforms.
Jason D
+3  A: 

Here's an example where you can add a print feature to the richtextbox. It's basically just copying the rich text to the Graphics object used for printing. I think you could modify this to use your own graphics object instead, and basically "print" to an image.

Edit:

Here's a post where someone seems to have modified the print code for creating an image.

Jon B
This is the answer I would have given. I've used a similar approach with a custom drawn treeview, in order to double buffer it, and it works wonderfully.
Jason D