formatted text in GDI+

A

Anders

I need to create a "text-object" for a drawing
application. (comparable to AutoCad multiline text)
Nothing fancy, except that it needs to support tables
with right or decimal aligned number columns. The text
must be edited in a wysiwyg editor, and then rendered at
the correct location on the GDI+ graphics (screen/printer
drawing)

I have tried the RichTextBox control, but it doesn't seem
versatile enough. My questions are:


1. How do I use the RichTextBox control to edit and then
subsequently paint the formatted text onto other GDI+
surfaces? The only solution I have seen is using some
interop hack to call the FormatRange function, can't it
be done without interop?

2. With or without interop: how do I make sure the
resolutions get correct on the render surface of the
FormatRange? Do I have to use another interop call to set
the render resolution?

3. Which is the easiest way to make a table with a right
aligned column? Is it even supported? I hear
AdvancedTypography can be enabled by yet another interop
call to give right aligned tabs (but how do I control
them in the RichTextBox? will they work as right-flush
tabs correctly in edit?). Does the RichTextBox support
any rtf "tables"?

4. If I give up on the RichTextBox, what oher methods are
recommended? Using the 10mb mshtml lib for displaying
some formatted text and simple tables feels a bit
overkill.

Any help is greatly appreciated.
 
X

Xin Huang [MSFT]

I'm afraid you really need some interops. Since RichTextBox is a wrapper to
the unmanaged Rich Edit Control, you can do anything wordpad can. The
source code of wordpad
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample/h
tml/_sample_mfc_WORDPAD.asp) may help you.

Hope this helps.

Regards,
Xin

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? Visit http://windowsupdate.microsoft.com to get the latest
critical updates and service packs available for your computer's Windows
operating system.
 
A

Anders

I'm afraid you really need some interops. Since RichTextBox is a wrapper to
the unmanaged Rich Edit Control, you can do anything
wordpad can.

Thanks for your reply,
Interop is fine if the result is ok, then it's just down
to:
-Can wordpad (the unmanaged rich edit control) do any
kind of table or a right aligned tab?
 
X

Xin Huang [MSFT]

Yes. If you just want a right-aligned table, you don't event need interop.
Instead, you need to insert some raw RTF text. Try this:

In Word, insert a table and format it as you wish. Copy and paste it to a
RichTextBox. There you get the RTF string of the content by getting the
RichTextBox.Rtf property. That's what you can insert into a RichTextBox by
setting the RichTextBox.SelectedRtf property. If you want to understand the
raw RTF string, you can download the RTF spec from
<http://www.microsoft.com/downloads/details.aspx?FamilyId=E5B8EBC2-6AD6-49F0
-8C90-E4F763E3F04F&displaylang=en>, or you can view it online at
<http://msdn.microsoft.com/library/en-us/dnrtfspec/html/rtfspec.asp>.

Hope this helps.

Regards,
Xin

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? Visit http://windowsupdate.microsoft.com to get the latest
critical updates and service packs available for your computer's Windows
operating system.
 

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