Visit my other favourite sites.. View my current favourite piece of software Download our software.... Source-code and tutorials.... Return back to the main page

How-To... - Use the ImageList control for animation

The ImageList control allows you to store images into this control and reference them, almost like an array. This control comes in handy for animation because it can be used alongside a timer with very little code.

This idea has been used in lots of software, most people will spot it in Norton products, and even in Killiesofts Celebrity Calculator.

Setting up the Form

On a new form, add an Image Control, ImageList, and a Timer. Give the Image Control the name imgAni , the ImageList the name ImageList and the Timer the name tmrTimer. Give the Timer an interval of 500.

Follow the steps to add your images to the ImageList control :-

The code

Open the General Declerations section of the form and insert the code below into it :-

'------------------------------------------------------------------
'VB How-To - Use the ImageList control for animation
'By David Cowan(david@cowan-creations.co.uk)
'Please do not re-distribute without permission
'------------------------------------------------------------------

'Create a counting variable for looping purposes...
Dim iCounter As Integer

Private Sub tmrTimer_Timer()
'--------------------------------------------------------
'In my opinion, this is one of the quickest
'ways to animate a group of images.
'
'This will run every time the timer is activated
', which is determined by the Timer Interval
'---------------------------------------------------------

'Add 1 to the counting variable...
iCounter = iCounter + 1

'Set the picture of imgAni to the image number
'iCounter(which are stored in the ImageList...
imgAni.Picture = ImageList.ListImages(iCounter).Picture

'If iCounter equals 8, set it back to 0 so that
'the animation continues.
'8 is the maximum amount of frames in this animation.
'Change this number to the number of frames to animate...
If iCounter = 8 Then iCounter = 0
End Sub

Finishing Up

If anything didn't make sense, you can download the Project File for this tip by clicking here


This site is Copyright © 1999 of David Cowan. VB How-To, Cowan Creations, Dodgesoft and DodgeSoft Productions is Copyright © 1999 of David Cowan. Source-code and programs are copyright of their respective owners. For a messageboard, click here