RichEdit scrolling without focus

I need to scroll RichEdit to the very end after adding a row. I have this RichEdit in a separate form that I don’t want to focus at all. I tried the often suggested solution:

RichEdit.Lines.Add(someText);
RichEdit.SelStart:=RichEdit.GetTextLen;
SendMessage(RichEdit.handle, EM_SCROLLCARET, 0, 0);

But this does not work for me. However, when I focus RichEdit before calling SendMessagewith RichEdit.SetFocus;, it works fine. This, however, destroys my other application needs.

I am using XE2. Thanks

+6
source share
2 answers

This is what I do:

SendMessage(RichEdit.Handle, WM_VSCROLL, SB_BOTTOM, 0);
+11
source

See this blog post by François Gaillard: richedit-on-scrolling-strike .

An error appears: here is a workaround:

procedure ScrollToEnd(ARichEdit: TRichEdit);
var
  isSelectionHidden: Boolean;
begin
  with ARichEdit do
  begin
    SelStart := Perform( EM_LINEINDEX, Lines.Count, 0);//Set caret at end
    isSelectionHidden := HideSelection;
    try
      HideSelection := False;
      Perform( EM_SCROLLCARET, 0, 0);  // Scroll to caret
    finally
      HideSelection := isSelectionHidden;
    end;
  end;
end;
+9
source

All Articles