Adding an Image on the

There is some unpredictability in adding images. Any given image might be shaped either landscape or portrait. The image might be small or huge. The strategy you might want to employ is to let the image load full size by setting the .AutoSize parameter to True before loading the image:

Name:=TC, Visible:=True

TC = "Image" & PicCount

Me.Controls.Add bstrProgId:="forms.image.1' Me.Controls(TC).Top = LastTop Me.Controls(TC).Left = LastLeft Me.Controls(TC).AutoSize = True On Error Resume Next

Me.Controls(TC).Picture = LoadPicture(fname) On Error GoTo 0

Then, after the image has loaded, you can read the control's Height and Width properties to determine whether the image is landscape or portrait and whether the image is constrained by available width or available height:

1 The picture resized the control to full size

' determine the size of the picture

Wid = Me.Controls(TC).Width

Ht = Me.Controls(TC).Height

WidRedux = CellWid / Wid

HtRedux = CellHt / Ht

If WidRedux < HtRedux Then Redux = WidRedux

Redux = HtRedux End If

After you find the proper size for the image to have it draw without distortion, you can set the AutoSize property to False and use the correct height and width to have the image not appear distorted:

' Now resize the control Me.Controls(TC).AutoSize = False Me.Controls(TC).Height = NewHt Me.Controls(TC).Width = NewWid

Me.Controls(TC).PictureSizeMode = fmPictureSizeModeStretch

0 0

Post a comment