Example #1
0
        private void Scroll(Point position)
        {
            RectangleF imageRectangle = form.CanvasRectangle.Scale(form.ZoomFactor);
            float      inMousePosition, inClientAreaSize, inImageSize;

            if (Orientation == Orientation.Horizontal)
            {
                inMousePosition  = position.X;
                inClientAreaSize = form.ClientArea.Width;
                inImageSize      = imageRectangle.Width;
            }
            else
            {
                inMousePosition  = position.Y;
                inClientAreaSize = form.ClientArea.Height;
                inImageSize      = imageRectangle.Height;
            }

            float mousePositionLocal = inMousePosition - Margin - Padding;

            float trackLength         = inClientAreaSize - (Margin * 2) - (Padding * 2) - Thickness;
            float trackLengthInternal = trackLength - (Padding * 2);

            float centerOffsetNew = ((trackLengthInternal / 2.0f) - mousePositionLocal) / trackLengthInternal * inImageSize;

            Vector2 canvasCenterOffset = Orientation == Orientation.Horizontal ?
                                         new Vector2(centerOffsetNew, form.CanvasCenterOffset.Y) :
                                         new Vector2(form.CanvasCenterOffset.X, centerOffsetNew);

            form.PanToOffset(canvasCenterOffset);
        }