Search code examples
delphirichedit

Scrolling issues with TRichEdit in Delphi


I am adding lines to a TRichEdit how do I keep focus on the line that has just been added?

For Idx := 1 to 1000 do
   RichEdit.Lines.add(IntToStr(Idx));

EDIT

I just what the bottom line of the richedit to show what was just added and all the other lines to scroll up


Solution

  • This should work, if you just want to scroll to the end of the richedit:

    For Idx := 1 to 1000 do
    begin
      RichEdit.Lines.add(IntToStr(Idx));
      RichEdit.SelStart := RichEdit.GetTextLen;
      SendMessage(RichEdit.handle, EM_SCROLLCARET,0,0);
    end;
    

    If this is not what you wanted, please see my comment above and clarify your question.