![](/img/trans.png)
[英]How to assign richly formatted text to Delphi TRichEdit or TcxRichEdit during design time (possibly, using Lines attribute)?
[英]How can I know if all the text is selected in a TRichEdit when the text has three or more lines?
我有一个带有一些RTF的 TRichEdit(仅带格式的文本),我想知道是否选择了 TRichEdit 的所有内容。 为此,我这样做:
var AllSelectd: Boolean;
//...
AllSelectd := MyRichEdit.SelLength = MyRichEdit.GetTextLen;
效果很好,除非内容有三行或更多行。 零到两行,一切都很好。 一旦我在 TRichEdit 中达到三行,上面的代码就不再有效( MyRichEdit.SelLength < MyRichEdit.GetTextLen
)。 每行都以 CRLF ( #13#10
) 结尾。
这是一个错误吗? 我怎样才能可靠地检查是否在 TRichEdit 中选择了所有内容?
我使用 Delphi 10.4,如果它有任何变化的话。
如本主题所述,RichEdit 2.0 在内部将 CRLF 对替换为 CR,并在某些情况下检索 LF。
作为解决方法 - 计算选定范围内的行数以进行更正( SelText
仅包含 CR, GetTextLen
处理带有检索到的 CRLF 的文本,因此计算 CR 和 LF)。 使用 Remy Lebeau 提案。
var
sel, getl, crcnt, i: integer;
tx: string;
begin
sel := RichEdit1.SelLength;
getl := RichEdit1.GetTextLen;
crcnt := SendMessage(Richedit1.Handle, EM_EXLINEFROMCHAR, 0, sel);
Memo1.Lines.Add(Format('%d %d',[sel, getl - crcnt + 1]));
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.