I have a TextArea that is used to implement a sort of terminal window. Text is added using AddText method and it can happen when not under the control of the user. I would like to shift the vertical scroll bar position automatically so that the most recently added text is visible at the bottom of the TextArea if there is enough text to fill the TextArea. The text is styled text.
At this point, I am rather stumped. Can anyone describe how to do this?
Many thanks
Jim Wagner
Oregon Research Electronics
Normally, the VerticalScrollPosition value is about the number of visible lines (IIRC, the index of the line that appears at the very top of the text area). But if your value is greater than the maximum possible value (i.e. the total number of lines in the control minus how many lines are visible), the scroll position will go to its maximum (like when you set a progress bar’s value beyond its maximum, it’ll go to the maximum).
Since you always have more characters than lines, setting the length of the text for the scroll position behaves as explained.
Emile’s solution works like a charm on MacOS. But on Windows (testing Win10) using 2019 R3.2, that method shifts the last line to the top of the screen. To be fair, the LR says:
Use this property to determine the first visible line; set this property to scroll the control. Setting it to the last line or beyond the last line will simply move the vertical scrollbar’s thumb to the bottom, not necessarily displaying the last line at the top of the control.
Can someone either suggest a general cross-platform method to shift text added to a TextArea using the AddText method so that the last line is visible at the bottom of the TextArea OR a Windows-specific method to do the same?
I have tried adjusting the thumb position using the TextArea.height property and the TextArea.LineHeight property but I keep getting 0.0 for the latter.
Many thanks
Jim Wagner
Oregon Research Electronics
textAreaTest.AddText(EndOfLine.Windows + "text")
var amountOfLineNumbers as integer = textAreaTest.LineNumber( textAreaTest.Value.Length )
for i as integer = 0 to amountOfLineNumbers
textAreaTest.VerticalScrollPosition = i
next
Wow, I can’t understand why we have to do this ourselves. Shouldn’t the AddText method automatically scroll into view? Who would want to add text and not see it? This seems like programming in the '90s without a GUI.
I certainly don’t want that to happen. Sorry. If I’m loading the contents of a dialog box prior to the user seeing it I don’t want the textareas scrolled to the bottom.