I'm currently trying to write a zoomable UserControl and I've currently followed Bob Powell's example at http://www.bobpowell.net/zoompicbox.htm, 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? thanks.
A:
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)
ChrisF
2009-10-30 11:20:36