FilePage Event example for Visual Basic

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 = ScaleHeight * 3 / 4
   WidthAllowed = ScaleWidth * 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 = ScaleWidth / 8
     Lead1.Width = WidthAllowed
     Lead1.Height = (Lead1.Width * HeightFactor) / WidthFactor
     Lead1.Top = (ScaleHeight - Lead1.Height) / 2
   Else
     Lead1.Top = ScaleHeight / 8
     Lead1.Height = HeightAllowed
     Lead1.Width = (Lead1.Height * WidthFactor) / HeightFactor
     Lead1.Left = (ScaleWidth - Lead1.Width) / 2
   End If

   ' Set the image display size to match the LEAD control.
   Lead1.AutoScroll = False
   Lead1.AutoSetRects = True
   Lead1.AutoRepaint = True
   Lead1.PaintSizeMode = PAINTSIZEMODE_FIT
End Sub