Picturebox and Timer for animation

Tylor

New member
Joined
Aug 20, 2014
Messages
4
Location
South Africa, Johannesburg
Programming Experience
Beginner
Morning Guys.

I am currently trying to loop through images in a picturebox.
Somewhat to create an animation.
I'm currently using one picturebox that I just change the image from, and stop/restart the timer each time:
        Timer1.Start()
        PictureBox1.Image = Image.FromFile("images.jpg")
        PictureBox1.Refresh()
        Timer1.Stop()
        Timer1.Interval = 1000
        Timer1.Start()
        PictureBox1.Image = Image.FromFile("Image2.png")
        PictureBox1.Refresh()

        Timer1.Stop()
        Timer1.Interval = 1000
        Timer1.Start()
        PictureBox1.Image = Image.FromFile("Image3.png")
        PictureBox1.Refresh()
        Timer1.Stop()
        Timer1.Interval = 1000
        Timer1.Start()
        PictureBox1.Image = Image.FromFile("Image4.png")
        PictureBox1.Refresh()
        Timer1.Stop()

It does change the images, but at suck a fast speed even though my Timer is set to 1 second.
Is there a way to rectify this or is my code absolutely ugly to look at and I should scrap it and do something else instead. Like an array with switch cases?
 
Last edited by a moderator:
You seem to have completely misunderstood how a Timer works. What exactly do you think those Start and Stop calls are doing? The way a Timer works is that you set the Interval property and call Start, then the Tick event is raised on that Interval. You're not handling the Tick event at all so your Timer is useless.

So, what you should be doing is creating the Image objects and put them into a list and then, in the Tick event handler of the Timer, you change the Image in the PictureBox to the next one in the list.
 
Back
Top