Recent

Author Topic: [SOLVED] Automatic scrolling in SynEdit  (Read 1610 times)

simone

  • Sr. Member
  • ****
  • Posts: 416
[SOLVED] Automatic scrolling in SynEdit
« on: October 12, 2021, 09:39:33 pm »
Sometimes I use the SynEdit component to show the textual outputs of some tasks. I noticed that if the number of lines exceeds the capacity of the control window, the automatic vertical scrolling upwards does not occur.

To solve this problem, at each operation that involves adding a row, I place the cursor to go beyond the last row, with:

Code: Pascal  [Select][+][-]
  1. SynEdit.CaretY: = SynEdit.Lines.Count

in order to force scrolling.

Is there a SynEdit option that allows me to achieve this effect without this workaround?

Thanks in Advance for the help.
« Last Edit: October 13, 2021, 09:34:53 am by simone »
Microsoft Windows 10 64 bit - Lazarus 2.0.12

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7529
  • Debugger - SynEdit - and more
    • wiki
Re: Automatic scrolling in SynEdit
« Reply #1 on: October 12, 2021, 10:33:06 pm »
You can set the SynEdit.TopLine instead.

Adding to SynEdit.Lines is a "raw" add. That is, it does not modify anything else. No caret move, no scroll. Not even undo-info. (I.e. after SynEdit.Lines.Add the undo info is cleared).

There is SynEdit.SetTextBetweenPoints (maybe also TextAtCaret, not sure) that can set the caret. But it is a whole lot more processing intensive. So if you just add to the end of the buffer, then adjust the top line
  SynEdit.TopLine := MaxInt;

Of course if the user scrolled up, you need to decide if you want to keep scrolling.

simone

  • Sr. Member
  • ****
  • Posts: 416
Re: Automatic scrolling in SynEdit
« Reply #2 on: October 12, 2021, 11:59:59 pm »
Thanks Martin. Your solution works perfectly.
Microsoft Windows 10 64 bit - Lazarus 2.0.12

 

TinyPortal © 2005-2018