How to stop the automatic scrolling of a Memo control?
Asked Answered
P

1

7

In Windows 7, a memo control (TMemo) will scroll automatically after text is insterted (Memo.Lines.Add(Path);), which I do not want, because scrolling is done by myself.

How can I stop the automatic scrolling?

Providential answered 29/12, 2012 at 8:9 Comment(2)
When the memo scrolls automatically?Emyle
when data is inserted. code: lstFiles.Lines.Add(Path);. lstFiles is TMemo.Providential
S
10

Normally, adding text to a memo control scrolls the memo to the bottom of the inserted text. To prevent that, call Lines.BeginUpdate before adding text, and call EndUpdate afterwards:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.BeginUpdate;
  try
    Memo1.Lines.Add('...');
    Memo1.Lines.Add('...');
    ...
  finally
    Memo1.Lines.EndUpdate;
  end;
end;
Scrubber answered 20/3, 2013 at 6:19 Comment(3)
This functions OK but have undesired side effect of flickering :-(. Setting DoubleBuffered property is of no benefit.Tolle
Can you explain why this works? In the documentation for System.Classes.TStrings.BeginUpdate it says "Some descendants of TStrings use this information to perform certain actions, such as telling a control to repaint, when updates are complete."Slink
@New Because TMemoStrings.SetUpdateState is implemented the way it is.Scrubber

© 2022 - 2024 — McMap. All rights reserved.