简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM