Scrolling to bottom of TextArea

How do I scroll to the bottom of a TextArea with code?

Because macOS hides the scrollbar by default I wanted to make a widget to show that more text is available when starting my app the first time.

I set the VerticalScrollPosition to 1000 to get the max scrollposition. There are 2 buttons to increase and decrease the scrollpostion. Then I have a timer to enable or disable the buttons:

if currentScrollPosition = 0 then
ElseIf currentScrollPosition = maxScrollPosition then
end if

Now the problem:The down button gets disabled before the TextArea has been scrolled to the bottom:

Bug or feature? Any ideas for a workaround?

Project is available at

Tested on macOS 10.13 and 12 with Xojo 2022r1.

I do not like the answer I am writing, but this is a solution: use a declare API (it certainly exists) to enable the Always (toujours below) RadioButton.

this comes from the System Preferences’ first entry (Général: don’t know its US or .de name) and is the way to set the scrollbar visible property (three values)… in French.


Whats your code to adjust the TextArea scrolling? To me the screenshot looks like the scrollbar has been adjusted, but not the clipView offset.

Edit: I don’t see any properties for getting the maximum scroll value either. I guess you need declares for that.

I’m doing that super simple:

Open event of the container:

isOpening = True
TextArea1.VerticalScrollPosition = 1000

Then there is a timer:

dim currentScrollPosition as Integer = TextArea1.VerticalScrollPosition

if isOpening then
  maxScrollPosition = currentScrollPosition
  TextArea1.VerticalScrollPosition = 0
  isOpening = False
end if

If I add an EndOfLine to my text then the buttons are okay.

1 Like

Final result:

My suggestion would be to use the multi-languages feature of Mac OS. For instance, whenever I reply to this forum (be it a screenshot or quoting the UI as text), I always go to System Preferences→Language & Region and put English to the top. Then I quit and relaunch the application I want to quote (if it’s System Preferences itself, proceed with caution to not answer “Restart now”, which would restart the computer), I take the screenshot or write down the text, go back to Language & Region and put English where it was.
That way (1) you know how to name the path you took to go there and (2) it’s much more easy for English readers to know what you’re showing.
I invite you to try.

I’m not exactly sure right now, but I think you can achieve what you want by playing with VerticalScrollPosition, InsertionPosition and LineNumber.

Something along those thoughts:
(1): me.LineNumber(me.Text.Length) gives you the index of the last line.

(2): me.LineNumber(me.InsertionPosition(me.width-1,me.height-1))-me.LineNumber(me.InsertionPosition(0,0)) tells you how many lines are shown on the TextArea (when there’s only a single style).

So if you set VerticalScrollPosition (=the first visible line) to (1)-(2) you’d get the right value.
I know it’s awkward, but I recall having seen acceptable results in the past.

1 Like

Are the contents of the Text Area editable? If not have you considered using HTML and Javascript to display the scroll button?