Available in the LEADTOOLS Imaging toolkit. |
AutoAnimate example for Visual Basic
Note: Also works with Access 95 and 97.
This example gets information about an animated file, uses the information to position the LEAD control, and plays the animation as it loads the file.
' Declare variables for positioning the control.
Dim DisplayWidth, DisplayHeight, DisplayLeft, DisplayTop
Dim HeightFactor, WidthFactor, HeightAllowed, WidthAllowed
' Force continued looping after the file loads.
Lead1.AutoAnimationLoop = AUTOANIMATIONLOOP_INFINITE
' Get information about the file we will load.
Lead1.GetFileInfo "c:\windows\system\wndsurf1.avi", 0, 0
' Exit if this is not an animated file.
If Lead1.InfoAnimation = False Then
MsgBox "Not an animated file", 0, "Error"
Else
' Calculate information for centering the LEAD control.
'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 properties for playing the animation as is loads.
Lead1.AutoAnimate = True
Lead1.AutoRepaint = True
' Load the animated file.
Lead1.Load "c:\windows\system\wndsurf1.avi", 0, 0, -1
End If