如何将文本附加到 RichEdit 控件的最后一行?
如何将文本添加到最后一行而不是新行? Lines.Add 和 Lines.Append 将文本添加为新行,而 Lines.Insert 需要一个我不知道如何找到的位置。
How can I add text not to a new line but to the last existing line? Lines.Add and Lines.Append add text as a new line, and Lines.Insert needs a position that I don't know how to find.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用最后一行本身或整个内容:
请注意,第一种方法更好,特别是当 RichEdit 包含大量文本时。读取和写入 RichEdit.Text 可能涉及在内存中移动大量文本。
编辑:在OP对我的答案发表评论后:
要格式化文本,请在添加之前保存SelStart,然后使用SelLength和SelAttributes应用格式:
You can use the last line itself, or the entire content:
Note that the first way is better, especially when the RichEdit contains a large amount of text. Reading and writing to RichEdit.Text can involve moving lots of text around in memory.
EDIT: After the OP's comment to my answer:
To format the text, save SelStart before adding, and then use SelLength and SelAttributes to apply formatting:
您可以使用“字符串”和“计数”属性。
RichEdit1.Lines.Strings[RichEdit1.Lines.Count-1]:=RichEdit1.Lines.Strings[RichEdit1.Lines.Count-1]+'文本';
You can use "Strings" and "Count" properties.
RichEdit1.Lines.Strings[RichEdit1.Lines.Count-1]:=RichEdit1.Lines.Strings[RichEdit1.Lines.Count-1]+'Text';
履行
Perform