autoscrolling memo in delphi – Stack Overflow
Posted by jpluimers on 2013/04/03
Just found this great answer by vcldeveloper to autoscroll a readonly logging memo in Delphi which works from Delphi 1 and up (:
For such a simple task, you don’t need to buy a commercial component! All you need to do is to send an EM_LINESCROLL message to that memo control, to make it scroll to the last line:
procedure ScrollToLastLine(Memo: TMemo); begin SendMessage(Memo.Handle, EM_LINESCROLL, 0,Memo.Lines.Count); end;If your memo is read-only to users and is updated automatically by the application, you can put a call to the above procedure in its OnChange event-handler, so that whenever the text inside the memo is changed, it is automatically scrolled down to the last line.
–jeroen
ObjectMethodology.com said
Nice!
Stefan said
Does this not work for you, which also works for RichEditMemos etc?
mLog.Perform(WM_VSCROLL, SB_BOTTOM, SB_THUMBTRACK);
jpluimers said
Will try this when logging to a readonly memo again.
sckfjsdhfjk said
i was wondering if there is a way to auto scroll the memo in a human reading pace?
sckfjsdhfjk said
you can
add a timer, that will scroll down by amount of lines each iteration, such as
procedure TForm1.Timer1Timer(Sender: TObject);
var
amountOfLines:integer;
begin
amountOfLines:=5;
SendMessage(Memo.Handle, EM_LINESCROLL, 0,amoutOfLines);
end;
sckfjsdhfjk said
so how do you do s cyclic scroll?
when you reach the end restart from the begining?
jpluimers said
Never had the need for that, so I don’t know. Sorry (:
dsfasdf ads s said
to scroll to top do:
Memo1.Perform(EM_SETSEL , 0, 0);
Memo1.Perform(EM_SCROLLCARET, 0, 0);
jpluimers said
Thanks!