user199382
user199382

Reputation: 1

Zoom to the center of view port

I'm currently trying to write a zoomable UserControl and I've currently followed Bob Powell's example at https://web.archive.org/web/20141229192708/http://bobpowell.net/zoompicbox.aspx, however, what I'm trying to achieve is zooming to the center point of the control, not the top left corner.

Is anybody having experience/idea on this?

Upvotes: 0

Views: 978

Answers (1)

ChrisF
ChrisF

Reputation: 137148

You need to offset the values of the control by the centre, apply the scale transform and then offset back.

Try the following algorithm to calculate the new top left:

(-old_centre * factor) + old_centre

If the control is 100,100 a zoom factor of 2 will produce:

((-50, -50) * 2) + (50, 50) = (-100, -100) + (50, 50) = (-50, -50)

With a zoom factor of 0.5:

((-50, -50) * 0.5) + (50, 50) = (-25, -25) + (50, 50) = (25, 25)

Upvotes: 1

Related Questions