views:

74

answers:

1

Question A.

Given

  1. A string in rich text format that may have paragraph, tabs, space, line break, indentation, (or even image?)
  2. A width for the word wrapping rich text control/editor

How do I know the height of the content after it have performed all the word wrapping? Is there something like

int MeasureRichTextHeightAfterWordWrap(string aRichTextContent, int aWidth)?

Otherwise how does those rich text control know how much to autosize?

Do I have to actually place the content on a dummy rich text control, set it's width and get its height with GetPositionFromCharIndex(TextLength-1) afterwards? Although this does work, it seems to be "wasteful"

Question B. If I draw plain text onto a plain text memo/control/editor, and manually draw string with manually calculated indentations, breaks, word wrappings to pretend the RTF.

Is it easier or harder?

Edited to make it look clearer and sorry if my English looks like a student cause it's not my native language.

+1  A: 

Sorry about my bad first attempt at an answer. I DID find an answer for measuring inside a RichTextBox. Apparently you have to use Win32 GDI API calls.

http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.windowsforms.controls/2004-09/0574.html

I found this by changing my search after running across this nugget, which explains why there's not a pure .NET way to do it:

http://www.developmentnow.com/g/38_2005_10_0_0_626243/I-dont-believe-this-code-gives-the-correct-RichTextBox-string-size.htm

David Stratton