1

I am adding lines of text to a TMemo using : Memo1.Lines.Add(Text), which causes Memo1 to scroll to the bottom.

Is there any way to either stop it scrolling as I add lines, or force it to go back to the top when I finished?

I want a simple solution...

Thanks...

Thomas Jomphe
  • 117
  • 6
  • 17
  • Possible duplicate of [How to stop the automatic scrolling of a Memo control?](http://stackoverflow.com/questions/14079906/how-to-stop-the-automatic-scrolling-of-a-memo-control) – Jan Doggen Oct 06 '16 at 12:10

2 Answers2

6

Set the Memo's SelStart property to 0 and then send an EM_SCROLLCARET message to the Memo.

Memo1.Lines.BeginUpdate;
try
  Memo1.Lines.Add(...);
  ...
  Memo1.SelStart := 0;
  Memo1.SelLength := 0;
  Memo1.Perform(EM_SCROLLCARET, 0, 0);
finally
  Memo1.Lines.EndUpdate;
end;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
4

You can use begin/end update for lines collection:

memo.Lines.BeginUpdate;
try
  memo.Lines.Add('test');
finally
  memo.Lines.EndUpdate;
end;
JayDi
  • 1,037
  • 15
  • 24