Thomas Jomphe
Thomas Jomphe

Reputation: 117

TMemo Scrolling in Delphi

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...

Upvotes: 1

Views: 4825

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 596387

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;

Upvotes: 6

JayDi
JayDi

Reputation: 1067

You can use begin/end update for lines collection:

memo.Lines.BeginUpdate;
try
  memo.Lines.Add('test');
finally
  memo.Lines.EndUpdate;
end;

Upvotes: 5

Related Questions