如何获取自动换行后富文本内容的高度?
问题 A.
给定
- 一个富文本格式的字符串,可能有段落、制表符、空格、换行符、缩进(甚至图像?)
- 自动换行富文本控件/编辑器的宽度
我如何知道内容的高度在执行完所有自动换行之后? 有类似
int MeasureRichTextHeightAfterWordWrap(string aRichTextContent, int aWidth) 的东西吗?
否则那些富文本控件如何知道自动调整大小多少?
我是否必须将内容实际放置在虚拟富文本控件上,设置其宽度并随后使用 GetPositionFromCharIndex(TextLength-1) 获取其高度? 虽然这确实有效,但似乎“浪费”
问题B。 如果我将纯文本绘制到纯文本备忘录/控件/编辑器上, 并手动绘制带有手动计算的缩进、中断、自动换行的字符串来假装 RTF。
是更容易还是更难?
编辑使其看起来更清晰 很抱歉,如果我的英语看起来像学生,因为它不是我的母语。
Question A.
Given
- A string in rich text format that may have paragraph, tabs, space, line break, indentation, (or even image?)
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于我第一次尝试回答的错误感到抱歉。我确实找到了在 RichTextBox 内进行测量的答案。显然你必须使用 Win32 GDI API 调用。
http: //www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.windowsforms.controls/2004-09/0574.html
我在运行这个金块后通过更改搜索发现了这一点,这解释了为什么没有纯粹的.NET方法来做到这一点:
http://www.developmentnow.com/g/38_2005_10_0_0_626243/I-dont- believe-this-code-gives-the- Correct-RichTextBox-string-size。嗯
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