Canvas Issues

Hello wonderful brains trusts :slight_smile:

I have a couple of things I wondered if you could assist with.

In a Mac app I have (for my own use) I have a canvas that displays a series of containers (ie my own scrolling list box of sorts).

It works well but the fist issue is that when scrolling the mouse it scrolls in the opposite direction to what I would consider the norm.

The code in the MouseWheel event is:

if not booItineraryScroll Then Exit
if deltaY < 0 And intItineraryBottom < canvasItinerary.Height Then Exit
if deltaY > 0 And intItineraryTop > canvasItinerary.Top Then Exit
var scrollDistance As Integer = deltaY * 2
YScroll_Itinerary = YScroll_Itinerary + scrollDistance
canvasItinerary.Scroll(0, scrollDistance)
intItineraryTop = intItineraryTop + scrollDistance
intItineraryBottom = intItineraryBottom + scrollDistance

The canvas is canvasItinerary and the intItineraryTop and intItineraryBottom are used to keep track of the top and bottom of the container array so it doesn’t scroll off the canvas. I have tried every combination of changing the +'s to -'s and >'s to <'s and vise versa but I can’t figure how to make it scroll in the opposite direction to what it is. I feel like it’s gonna be something simple but I can’t work it out.

The other question is, in response to clicking on something, I want the canvas to shorten to reveal something underneath. It’s easy to do by altering the height but for aesthetics I’d like it to visually shorten in a “scrolling” manner. Not too long, but enough to notice.

Am I on the right track with:
for I As integer = canvasItinerary.height DownTo 650

But, obviously I then need to slow it down. I feel like the Timer will be involved here but I don’t understand that very well.

Any help on these, GREATLY appreciated.

Have you considered

var invertby as integer = -1
var scrollDistance As Integer = deltaY * 2 * invertby

You can set invertby to 1 or -1 based on a preference, if you wish
Don’t forget, the direction that your trackpad / mousewheel scrolls is ITSELF a user preference - I like mine backwards to that which Apple thinks is the norm.

That is Windows norm…

Everyone’s taste is good taste !

The problem rise when you move from a computer to another with different OS…

Thanks Jeff.

This creates a problem tho. In my code, it keeps track of the top of the first container in relation to the top of the canvas and the bottom edge of the lowest container and it’s position to the bottom of the canvas. The first 2 lines then check and exit the method if they are already there, thereby avoiding having the container scroll up or down off the screen.

What happens when I add your lines, is the direction is correct but, as soon as one of the edges goes past it’s respective boundary, it only continues that way and I cannot scroll it back again.

I hope I’ve described that clearly. :wink:

You’re right about the setting on a Mac. The problem here is that in my app it is going opposite to the way I have it everywhere else.


Just for reference, when I push forward on my mouse/trackpad etc, whatever I am looking at scrolls up whilst pulling back scrolls down.

Not sure if that’s everyone’s norm or not, it feels right to me tho :slight_smile:

I’m struggling to work out what your code does, but my guess is that the problem you are NOW seeing stems from

if deltaY < 0 And intItineraryBottom < canvasItinerary.Height Then Exit
if deltaY > 0 And intItineraryTop > canvasItinerary.Top Then Exit

What you should do is
-establish the InvertBy value - should it be +1 or -1
-calculate the scrollDistance
-decide if applying the scrollDistance will make things go too far
-if so, reduce the scrollDistance to the maxmimum it could be , while being valid
-apply the change (which may be no change if the distance works out as 0)


In a space 300 tall, where an object can scroll up or down

//calculate scrolldistance , and then...

If + object.height  + scrollDistance  > 300   then = 300 - object.height
end if

If  + scrollDistance  < 0   then = 0
end if

or if there are lots of objects, nobble the scrolldistance based on the topmost and bottommost objects

//calculate scrolldistance , and then…

If + lowestobject.height + scrollDistance > 300 then
scrollDistance = scrollDistance - ( ( + lowestobject.height + scrollDistance)-300)
end if

If + scrollDistance < 0 then
scrollDistance = scrollDistance + ( scrollDistance - )
end if

//now apply scrolldistance to all objects

Jeff, thanks again, I’ll have a look at what you’ve proposed.

Just to explain, those first 2 lines. I created 2 variables to keep track of where the top and bottom of the array are. Then, if deltaY < 0 I am trying to scroll up, so it checks if the bottom of the array is already at the bottom of the canvas. If it is, it exits without processing. Similar with deltaY being > 0 and therefore scrolling down. There is a check against the top of the canvas etc.

It works fine, just can’t figure out how to make it work in reverse.

I’ll look thru what you’ve proposed.