I have a WinForms empty panel, and I’m adding images dynamically to this panel.
To center the first image added, I just:
- Get the width (WP) of the panel and divide by 2;
- Get the width (WI) of the image and divide by 2;
- WP – WI = Left position of image X;
But I can’t figure out some dinamically way to set this position when I have more than one image. Is there a way to calculate this X ? Am I right about this? Is there a easier way?
Thanks.
Well if you have only one row, some where you can have a collection of
Imageobjects, sayList<Image> images.And method
Should work to you, but you will need to check it. For example I suppose here that
tolalWidthof all images in collection is always less thenpanel.Width.