FilePage Event Example for Access 95 and 97

This example shows how the FilePage event can be used to size and position a lead control when an image is loaded.

Private Sub Lead1_FilePage()
   Dim HeightFactor, WidthFactor  ' Factors for aspect ratio
   Dim HeightAllowed, WidthAllowed  ' Maximum width and height
   Dim Width, Height, Left, Top  ' Variables for control dimensions

   ' 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 = Lead1.InfoHeight
   WidthFactor = Lead1.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
     Lead1.Left = Me.WindowWidth / 8
     Lead1.Width = WidthAllowed
     Lead1.Height = (Lead1.Width * HeightFactor) / WidthFactor
     Lead1.Top = (Me.WindowHeight - Lead1.Height) / 2
   Else
     Lead1.Top = Me.WindowHeight / 8
     Lead1.Height = HeightAllowed
     Lead1.Width = (Lead1.Height * WidthFactor) / HeightFactor
     Lead1.Left = (Me.WindowWidth - Lead1.Width) / 2
   End If

   ' Turn off scroll bars and automatic display rectangles.
   Lead1.AutoScroll = False
   Lead1.AutoSetRects = False

   ' Set the image display size to match the LEAD control.
   Lead1.SetDstRect 0, 0, Lead1.ScaleWidth, Lead1.ScaleHeight
   Lead1.SetDstClipRect 0, 0, Lead1.ScaleWidth, Lead1.ScaleHeight
   Lead1.ForceRepaint ' Repaint the image
End Sub