Scrollbar nightmare

Hi everyone.

I have been trying to get a window to scroll for TWO DAYS!!!, with absolutely no success, so I am now changing my approach.

I have a window with a container control. Inside the container control I have numerous buttons.

I am trying to link a scrollbar to the container control. so that I can scroll the contents inside.

I have looked at the language reference for both the “scrollbar” and the “container control”. I cannot find any information on how to link the 2 together???

The language reference makes total sense to someone who know’s what they are doing, but for me personally (a part time hobbyist), the reference makes absolutely no sense.

I have dragged a scrollbar onto my window, placed it next to the container (named “container1” ) - but I have no idea how to make the scrollbar scroll the container??

If there was a simple example project (even with no explanations), at least I could pick apart the project and work out from the code what is happening and how it works, but without an example, and simply having to look at a language reference which means nothing to me - it’s nigh on impossible.

Any help appreciated, as spending days on a stupid problem like this is destroying my soul :frowning:

You have a thing on a window.
The thing is (say) 2000 pixels high.
The window is (say) 900 pixels high
So at any time, you can show maybe just under half of the thing.

The scrollbar can govern where the thing is placed.

Scrollbar max value is Windowheight - thingheight
(in our example, thats a range of 0 to 1100)

In the scrollbar value change event/s,
Set to be scrollbar.value * -1

At the maximum value, the bottom 900 pixels of the thing will be visible.

Note that if the window size changes, you need to reset the scrollbar maximum and the value

As with all coding, there are other ways to do this, and I am sure some will arrive below.


/Applications/Xojo/Example Projects/Graphics and Multimedia/CanvasScrolling.xojo_binary_project


I’m surprised there’s not an actual example for this in the examples, here’s some code I wrote a long time ago now for a bug report, if you’re coding this for windows on an older version than current you might need to see the code behind the “Flicker Fix” checkbox:

and here’s a link to the ball image used in the project


Thank you everyone - I will look into these replies.

Thanks Julian for the example - hopefully I can work it out from there (Im using macOS 11 with the latest Xojo)

I’ve just added a line of code to window1.resizing to account for the scrollbar height change if you change the window size, redownload the project and you should see it. This was a bug test and wasn’t really a fully working demo or pretty, so there’s probably some other missing bits :wink: let us know if you get stuck.

The dropbox link says that the item was deleted.

Interesting, I guess dropbox or the forum has changed of late so replacement of files causes a new id, thanks link updated.

1 Like