I like to create a smooth slowing scroll effect after panning an image in a scrollbox. Just like panning the map in maps.google.com. I’m not sure what type it is, but exactly same behaviour: when dragging the map around with a fast move, it doesn’t stop immediately when you release the mouse, but it starts slowing down.
Any ideas, components, links or samples?
The idea:
As per your comment, it should feel like Google Maps and thus while dragging the image, the image should stick to the mouse pointer; no special effects required so far. But at releasing the mouse button, the image needs to move (the scroll box needs to pan) further in the same direction and with a gradually easing speed, starting with the dragging velocity at the moment the mouse button was released.
So we need:
OnMouseMovewill work,Setup:
TScrollBoxon your form, create event handlers forOnMouseDown,OnMouseMoveandOnMouseUpand set theDoubleBufferedproperty toTrue(this needs to be done runtime),TTimeron your form, set its interval to 15 milliseconds (~ 67 Hz refresh rate) and create an event handler forOnTimer,TImageon the scroll box, load a picture, set the size to something big (e.g. 3200 x 3200), setStretchtoTrueand setEnabledtoFalseto let the mouse events through to the scroll box.Code (for scroll box):
Code (for panel):
And in case you do not want the scroll bars then use the following code. The example uses a panel as container, but that could be any windowed control or the form itself.
Code (for paint box):
And when the image’s dimensions are limitless (e.g. a globe), you can use a paint box to glue the image’s ends together.