Simon
Simon

Reputation: 25984

How do I render rich text to an image?

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.

Upvotes: 4

Views: 2926

Answers (2)

user27414
user27414

Reputation:

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.

Upvotes: 5

Noldorin
Noldorin

Reputation: 147240

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.

Upvotes: 0

Related Questions