views:

113

answers:

1

Hello all!

I have a Delphi form with TImages on it. Actually, it's a "fake" desktop with "icons" (the TImages).

When the user resizes the form (scales it or maximizes it, for example) the icons on the form should align proportionally.

Right now, I'm doing something like this with the images:

ImageX.Left:=Round(ImageX.Left * (Width / OldWidth));
ImageX.Top:=Round(ImageX.Top * (Height / OldHeight));

Now this is OK, as long as I start to make the maximized form smaller.

In that case the rightmost images are cut in part by the form's border (they're off the form's client area).

If I reposition these images to fit the client area, then the position of the icons get distorted upon scaling back to maximum size.

Any ideas for a better algorithm/fix?

Thanks!

+5  A: 

First of all, you can't have a correctly scaled desktop when you only move the images, and don't scale them as well. You can do slightly better by moving the midpoints of your images, not their top left corner. It still won't be perfect, but it will work better. Of course, now the images will be cropped on all four sides, not just bottom and right, but at least it will be symmetrical :-)

Second, you will get accumulative rounding errors since you constantly override the "original" values (ImageX's top and left coordinate). You'd be better off having the original values stored in some sort of collection or array, and setting the new position based on the original value, rather than the previous value.

Something like this:

ImageX.Left:=Round(ImageX_OriginalLeft * (Width / Original_Width));
Svein Bringsli