Jump to content

Check out our Community Blogs

- - - - -

Image Slideshow on Windows Form C# with Timer Control

  Posted by Barnsite, 07 December 2012 · 3952 views

Quick example of how to display an image control that loops through a folder of images.
Firstly drop a timer control onto your form (name: tmrNextImage), set the Interval to 1000 milliseconds (1 second) and set enabled to true.
Next drop a PictureBox control onto your form (name: imgPicture) and set SizeMode to Zoom (this will force your image to fit the box), drag your box to any size you like.
Now we need some images. I copied images to a folder (C:Data_StoreImages) and named them Logo1.jpg, Logo2.jpg, etc up to Logo6.jpg
Now lets make the code to load the image into the PictureBox control. We need a variable to ‘remember’ our image count, in this case imageNumber. Our loadNextImage checks to see if we’ve reached 7 (one more than the number of images we have) and if so sets imageNumber back to 1.
We then set the ImageLocation to our C:Data_storeimages plus our image name with the imageNumber inserted into the filename, e.g. Logo1.jpg the first time round. And then increment imageNumber by 1.

private int imageNumber = 1;

private void loadNextImage()
if(imageNumber == 7)
imageNumber = 1;
imgPicture.ImageLocation = string.Format(@"C:data_storeimageslogo{0}.jpg",imageNumber);

So now we need to trigger the image to change. To do this we use the Tick event of the timer (which will happen every 1000 milliseconds as we set earlier). So each time the tick event happens we call the loadNextImage code.

private void tmrNextImage_Tick(object sender, EventArgs e)

Now when you open the form the image should change every second.
http://feeds.wordpre...dpress.com/515/ Posted Image


  • 0

My Picture

0 user(s) viewing

0 members, 0 guests, 0 anonymous users


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download