Forum > SynEdit

[SOLVED] Automatic scrolling in SynEdit


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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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.

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.

Thanks Martin. Your solution works perfectly.


[0] Message Index

Go to full version