How to get the height of rich text content after word wrap?

Question A.

Considering

  • A rich text string that can contain a paragraph, tabs, space, line break, indentation, (or even an image?)
  • Width for text control / text content editor

How do I know the height of the content after it has done all the word wrap? There is something like

int MeasureRichTextHeightAfterWordWrap (string aRichTextContent, int aWidth)?

Otherwise, how does this rich text control know how long it takes to autosave?

Should I actually position content in a dummy text control, set its width, and get its height using GetPositionFromCharIndex (TextLength-1)? While it does work, it seems "wasteful"

Question B. If I draw simple text on a text note / control / editor, and manually draw a line with hand-calculated highlights, breaks, word wrap to pretend to be RTF.

Easier or harder?

Edited to make it clearer and sorry if my english looks like a student because it is not my native language.

+2


a source to share


1 answer


Sorry for my unsuccessful first attempt at an answer. I DID find an answer for measuring inside the RichTextBox. Obviously, you should be using 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 modifying my search by going through this nugget, which explains why there is no clean .NET way:

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

+1


a source







All Articles