-
Hello All,
As the subject line say's, I would like to center graphics (pictures) in a picturebox control.
A) The pictureboxes border is fixed, creating a nice viewable frame.
B) I would like to center to fit large, small, and irregularly shaped pictures. Maintaining the aspect ratio of those pictures. An example of an irregularly shaped picture would be one that is taller than it is wide etc.....
I am able to display and center these types of pictures on a full sized screen (form), but unable to do so in a picturebox. I have tried the following:
Putting an imagebox on the picturebox and find that any image that is put in the image box is displayed on the form behind the picturebox.
Putting a second picturebox on the first one, the picture doesn't display within the first one. It kind of hovers above it, though it may be centering on the form, I'm not sure if this is the case though.
An imagebox set to stretch, distorts the irregularly shaped pictures. I can change the shape of the fixed imagebox so pictures are less or not distorted at all. This makes the GUI look terrible.
Does anyone have any ideas about what would work and allow me to do this? API calls might do it however I'm not sure how to proceed in doing that. Hmm... I've just recalled seeing something about placing pictures in rich textboxes some where, I'll look for that after I've posted this. If anyone has any ideas, suggestions, etc... I would appreciate it.
Thanks in advance.
-
How about simply putting another picturebox inside the 'nice viewport', set it's AutoSize property to True and BorderStyle to None, and run code something like this:
(picViewport is the large picturebox with the border you described and picImage is the actual image)
Code:
picImage.Picture = LoadPicture("C:\Blabla.bmp")
With picImage
.Top = (picViewport.ScaleWidth - picImage.Width) / 2
.Left = (picViewport.ScaleHeight - picImage.Height) / 2
End With
-
case analysis
compare > the ratios between width and height for both the picture and the frame and base the resizing ratio on framewidth/picturewidth in first case and frameheight/pictureheight in second case