FilePage Event Example for Visual Basic

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

'Declare the RasterIO object WithEvents
Public WithEvents RasterIO As LEADRasterIO

'Use Load to load an image
RasterIO.Load LEADRasterView1.Raster, "d:\temp\24bit.bmp", 0, 1, 1

Private Sub RasterIO_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 = RasterIO.InfoHeight
   WidthFactor = RasterIO.InfoWidth
   HeightAllowed = ScaleHeight * 3 / 4
   WidthAllowed = ScaleWidth * 3 / 4
   'Center the LEAD RasterView 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
     LEADRasterView1.Left = ScaleWidth / 8
     LEADRasterView1.Width = WidthAllowed
     LEADRasterView1.Height = (LEADRasterView1.Width * HeightFactor) / WidthFactor
     LEADRasterView1.Top = (ScaleHeight - LEADRasterView1.Height) / 2
   Else
     LEADRasterView1.Top = ScaleHeight / 8
     LEADRasterView1.Height = HeightAllowed
     LEADRasterView1.Width = (LEADRasterView1.Height * WidthFactor) / HeightFactor
     LEADRasterView1.Left = (ScaleWidth - LEADRasterView1.Width) / 2
   End If
   ' Set the image display size to match the LEAD RasterView control.
   LEADRasterView1.AutoScroll = False
   LEADRasterView1.AutoSetRects = True
   LEADRasterView1.AutoRepaint = True
   LEADRasterView1.PaintSizeMode = PAINTSIZEMODE_FIT
End Sub