TextArea.txt.verticalscrollposition shows text area blank until clicked on in Windows

I have some simple code that adds text to the end of a textarea control. After the text is added, I want to scroll to the end of the textarea displaying the most recent text added. I basically get the length of the textarea and use that to set the vertical scroll position. This works as I expect in MacOS and Linux. In windows, it does work but the text does not show until I click on the scrollbar which is already the end as I intended.

I’ve tried doing a textarea.text.referesh, no difference. Pulling my hair out on this one as I understand the code needed, I see it work properly except in windows with the not visible as mentioned above.

Anyone run into this and have suggestions?

I think the Xojo documentation says Windows needs the control to have Focus for these changes to occur, so I suggest a myTextArea.SetFocus before you set the vertical scroll position in code.

Hi David,

This eliminates the issue where it doesn’t show text until I click. What’s happening now, is that the vertical scrollposition doesn’t seem to work it jumps back up to the very top. The following code shows what works just fine for Mac and Linux. And what isn’t for Windows. With MacOS and Linux, it just goes right to the end of the text. As mentioned, it is either jumping back to the top or not going to the end (too fast to see).

var NotesLength as integer
NotesLength=winMain.txt_notes.text.length

if targetlinux or targetmacos then
  winMain.txt_notes.VerticalScrollPosition = NotesLength
  winMain.txt_notes.Refresh(True)
end if


if TargetWindows then
  winMain.txt_notes.SetFocus
  winMain.txt_notes.VerticalScrollPosition = NotesLength
end if

Wouldn’t that be better as:

var NotesLength as integer
NotesLength=winMain.txt_notes.text.length

#if targetlinux or targetmacos then
  winMain.txt_notes.VerticalScrollPosition = NotesLength
  winMain.txt_notes.Refresh(True)
#endif


#if TargetWindows then
  winMain.txt_notes.SetFocus
  winMain.txt_notes.VerticalScrollPosition = NotesLength
#endif

Then it doesn’t get compiled into the executable if it isn’t required, rather than deciding each time it is run?

Thanks for the suggestion. I don’t see this resolving this issue though.

1 Like

Upon more testing, I can see what’s going on, but I’m not sure how to resolve it.

In MacOS and Linux, when set the VerticalScroll Position, it works fine. In Windows, it appears to set the scroll position and then immediately jump back to the very top. This is frustrating as this seems like something that Xojo should deal with consistently across the OS’s regardless of what needs to be done for an OS.