Charles Faiga
Charles Faiga

Reputation: 11753

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

Upvotes: 1

Views: 4487

Answers (2)

Argalatyr
Argalatyr

Reputation: 4659

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.

Upvotes: 5

RRUZ
RRUZ

Reputation: 136391

You can try this

option 1) set the cursor when the loop finish

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

RichEdit.SetFocus;
RichEdit.SelStart := RichEdit.Perform(EM_LINEINDEX, RichEdit.Lines.Count-1, 0) ;

option 2) set the cursor while the loop is executing

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

RichEdit.SelStart := RichEdit.Perform(EM_LINEINDEX, RichEdit.Lines.Count-1, 0) ;

Bye.

Upvotes: 3

Related Questions