Quote:
> I have an image control with its stretch propery set to true.
On top of the
> image, I have placed an icon. Now, if I resize the image, I
want the icon
> to move to the new location. Is there an easy way of
calculating the new
> co-ordinates of the icon?
To translate the center of the icon's position, you can do
something like this:
'this is the position of imgStretch -- before resizing
Dim fBeforeLeft as Single
Dim fBeforeTop as Single
Dim fBeforeWidth as Single
Dim fBeforeHeight as Single
'position of icon's center point
Dim fCenterX as Single
Dim fCenterY as Single
'determine center point before, in "before stretch" units
fCenterX = (imgIcon.Left - fBeforeLeft) / fBeforeWidth
fCenterY = (imgIcon.Top - fBeforeTop) / fBeforeHeight
'translate center point into "after stretch" units
fCenterX = fCenterX * imgStretch.Width + imgStretch.Left
fCenterY = fCenterY * imgStretch.Height + imgStretch.Top
'position the icon image
imgIcon.Move fCenterX - imgIcon.Width / 2, _
fCenterY - imgIcon.Height / 2
imgIcon.ZOrder vbBringToFront