PaintWhileLoad example for Access 2.0

This example causes the LEAD control to paint the image as it loads.

Me![LEAD1].Object.PaintWhileLoad = TRUE

'Get information about the image so that we can size the control.
Me![LEAD1].Object.GetFileInfo "c:\lead\images\image2.cmp", 0, 0

'Set the variables used for preserving the aspect ratio.
'Allow for a border of 1/8 of the form size.
'The units of measure do not matter, since we are calculating proportions.
HeightFactor = Me![LEAD1].Object.InfoHeight
WidthFactor = Me![LEAD1].Object.InfoWidth
HeightAllowed = Me.WindowHeight * 3/4
WidthAllowed = Me.WindowWidth * 3/4

'Center the LEAD control on the form, preserving the aspect ratio.
'Check to see if using the maximum width will make the image too tall.
'Set the dimensions based on the result.
If ((WidthAllowed * HeightFactor) / WidthFactor) < HeightAllowed Then
    Me![LEAD1].Left = Me.WindowWidth / 8
    Me![LEAD1].Width = WidthAllowed
    Me![LEAD1].Height = (Me![LEAD1].Width * HeightFactor) / WidthFactor
    Me![LEAD1].TOP = (Me.WindowHeight - Me![LEAD1].Height) / 2
Else
    Me![LEAD1].TOP = Me.WindowHeight / 8
    Me![LEAD1].Height = HeightAllowed
    Me![LEAD1].Width = (Me![LEAD1].Height * WidthFactor) / HeightFactor
    Me![LEAD1].Left = (Me.WindowWidth - Me![LEAD1].Width) / 2
  End If

'Set the image display sizes to match the LEAD controls
ImageHeight = Me![LEAD1].Object.ScaleHeight 
ImageWidth = Me![LEAD1].Object.ScaleWidth
BitmapHeight = Me![LEAD1].Object.InfoHeight
BitmapWidth = Me![LEAD1].Object.InfoWidth
Me![LEAD1].Object.SetSrcRect 0, 0, BitmapWidth, BitmapHeight
Me![LEAD1].Object.SetSrcClipRect 0, 0, BitmapWidth, BitmapHeight
Me![LEAD1].Object.SetDstRect 0, 0, ImageWidth, ImageHeight
Me![LEAD1].Object.SetDstClipRect 0, 0, ImageWidth, ImageHeight

'Turn off the automatic adjustment of display rectangles
Me![LEAD1].Object.AutoSetRects = False

'Load the file
Me![LEAD1].Object.Load "c:\lead\images\image2.cmp", 0, 0, 1

'Turn on the automatic adjustment of display rectangles for future use
Me![LEAD1].Object.AutoSetRects = True