如何自动滚动到 RichEdit 的末尾?

发布于 2024-11-15 21:05:08 字数 255 浏览 9 评论 0 原文

我以前从来不需要使用 TRichEdit,总是使用 TMemo。

当我添加像 TMemo 这样的文本时,我希望 RichEdit 自动滚动到最后。添加一些数据后查看它的外观:

在此处输入图像描述

正如您所看到的,滚动条仍然位于顶部,但我希望在添加文本时它保留在底部。

我已经“谷歌搜索”解决方案,但找不到一个好的且可靠的解决方案。

I never needed to use the TRichEdit before, always used TMemo.

I'd like RichEdit autoscrolling to the end when I add text like TMemo. See how it looks after you add some data:

enter image description here

As you can see, the scroll bar remains at the top, but I'd like it stayed at the bottom as I added text.

I've 'googled' for solutions but I couldn't find a good and reliable one.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

↙厌世 2024-11-22 21:05:08

试试这个代码

RichEdit1.SetFocus;
RichEdit1.SelStart := RichEdit1.GetTextLen;
RichEdit1.Perform(EM_SCROLLCARET, 0, 0);

Try this code

RichEdit1.SetFocus;
RichEdit1.SelStart := RichEdit1.GetTextLen;
RichEdit1.Perform(EM_SCROLLCARET, 0, 0);
淡笑忘祈一世凡恋 2024-11-22 21:05:08

这是更简单快捷的解决方案:

在 OnChange 事件处理程序中只需:

SendMessage(RichEdit1.handle, WM_VSCROLL, SB_BOTTOM, 0);

原始答案来自:https://www.experts-exchange.com/questions/21002277/Richedit-autoscrolling.html

Here is much easier and fast solution:

In OnChange event handler just:

SendMessage(RichEdit1.handle, WM_VSCROLL, SB_BOTTOM, 0);

Original answer from: https://www.experts-exchange.com/questions/21002277/Richedit-autoscrolling.html

各空 2024-11-22 21:05:08

简而言之,您需要将光标放在末尾,或者发送代码向下滚动。

你尝试过吗

Richedit1.SelStart :=RichEdit1.GetTextLength();
SendMessage(RichEdit1.handle, EM_SCROLLCARET,0,0);

In short, you need to place the cursor at the end, or send code to scroll down.

Have you tried

Richedit1.SelStart :=RichEdit1.GetTextLength();
SendMessage(RichEdit1.handle, EM_SCROLLCARET,0,0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文