简体   繁体   English

如何在设计时将格式丰富的文本分配给 Delphi TRichEdit 或 TcxRichEdit(可能使用 Lines 属性)?

[英]How to assign richly formatted text to Delphi TRichEdit or TcxRichEdit during design time (possibly, using Lines attribute)?

I just want to assign immutable, richly formatted text to RichEdit (or DevExpress cxRichEdit, which, obviously is inherited from VCL RichEdit) during design time.我只想在设计时将不可变的、格式丰富的文本分配给 RichEdit(或 DevExpress cxRichEdit,它显然是从 VCL RichEdit 继承的)。 I know how to do a lot of formatting during run-time using Selection of text and setting attributes to this selection.我知道如何在运行时使用文本选择和设置该选择的属性来进行大量格式化。 But I have no need for this flexibility - I just have long text with some words in bold and there is no need to modify it in runtime, this is some information/documentation for the user.但我不需要这种灵活性——我只是有一些粗体字的长文本,不需要在运行时修改它,这是给用户的一些信息/文档。

How can I assign such text during design time?我如何在设计时分配这样的文本? RichEdit does not have sophisticated editor (at least I can not find it) for the Lines attribute. RichEdit 没有针对 Lines 属性的复杂编辑器(至少我找不到)。 I tried to create RTF document in Word and then copy-paste its value (text with RTF markup) into Lines attribute, but then RichEdit shows all the RTF markup.我尝试在 Word 中创建 RTF 文档,然后将其值(带有 RTF 标记的文本)复制粘贴到 Lines 属性中,但随后 RichEdit 显示了所有 RTF 标记。 Besides, Word adds incredibly lot of RTF additional information, not just some RTF tags here and there.此外,Word 添加了令人难以置信的大量 RTF 附加信息,而不仅仅是到处都是一些 RTF 标签。

How to add formatted text in design time?如何在设计时添加格式化文本?

IMO this is not possible to add formatted text at design time. IMO 这不可能在设计时添加格式化文本。

You can load it at run time:您可以在运行时加载它:

RichEdit1.Lines.LoadFromFile(FileName);

I agree with @fpiette, it's not possibile to load formatted text into TRichEdit at design time, but it's possibile to add it to the project at design time and load it into TRichEdit at runtime.我同意@fpiette,不可能在设计时将格式化文本加载到 TRichEdit 中,但可以在设计时将其添加到项目中并在运行时将其加载到 TRichEdit 中。

You can add a.rtf file as a RCDATA resource and then load it, for example, during form creation:您可以将 .rtf 文件添加为 RCDATA 资源,然后加载它,例如,在创建表单期间:

procedure TMainForm.FormCreate(Sender: TObject);
var
  LRes: TResourceStream;
begin
  LRes := TResourceStream.Create(HInstance, 'DOCUMENT', RT_RCDATA);
  try
    RichEdit1.Lines.LoadFromStream(LRes);
  finally
    LRes.Free;
  end;
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM