How to autoscroll to the end of RichEdit?

久未见 提交于 2019-12-10 12:48:05

问题


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:

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.


回答1:


Try this code

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



回答2:


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




回答3:


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);


来源:https://stackoverflow.com/questions/6372193/how-to-autoscroll-to-the-end-of-richedit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!