Delphi中如何获取RichEdit的文本范围
有谁知道如何获取 TRichEdit 控件中文本的宽度和高度,就像在 TCanvas 上使用 TextWidth 和 TextHeight 一样?
我需要知道这样做的原因是我在不可见的表单上有一个 RichEdit,我使用 Richedit.Perform(EM_FORMATRANGE, ...) 将其内容复制到画布。问题是 EM_FORMATRANGE 需要一个 TFormatRange 类型的参数,其中指定目标矩形,但我不知道该矩形应该是什么,因为我事先不知道 RichEdit 中内容的大小。希望这是有道理的。
Does anyone know how to get the width and height of text in a TRichEdit control, in the same way that you would use TextWidth and TextHeight on a TCanvas?
The reason I need to know this doing this is I have a RichEdit on a non-visible form that I copy the contents of to a canvas using Richedit.Perform(EM_FORMATRANGE, ...). The problem is that the EM_FORMATRANGE requires a parameter of type TFormatRange in which the target rect is specified, but I don't know what the rect should be because I don't know in advance the size of the contents in the RichEdit. Hope that makes sense.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
再次使用 EM_FORMATRANGE 进行测量,请参阅 EM_FORMATRANGE 消息 在 MSDN 上:
通常,您已经有了一个具有宽度和高度的目标区域,您可以在其中进行绘图,例如在纸张上打印或在预定义的表面上生成预览。预定义宽度以获得所需高度的最简单示例可能是:
有关更完整的示例,请参阅 本文,或一般任何 RichEdit 预览/打印代码...
Again use EM_FORMATRANGE for measuring, see EM_FORMATRANGE Message on MSDN:
Generally you would already have a destination area, which has a width and height, where you'd do the drawing, like printing on a paper or producing a preview on a predefined surface. A most simple example for a predefined width to get the required height could be;
For a more complete example see this article, or in general any RichEdit previewing/printing code...
我从我的 Delphi LightSaber 库中提取了此代码。
当您向其添加行时,该组件会自行调整大小(而不是显示垂直滚动条)。您对 LineHeight 变量感兴趣:
I extracted this code from my Delphi LightSaber library.
The component resizes itself as you add lines to it (instead of showing the vert scrollbars). You are interested in LineHeight var: