How to Create an Image Slide Show in C#

In this tutorial, I will teach you how to create an image slide show in c#. This method has the ability to preview the list of images in a picture box one at a time. This is a simple method that can be used in a school project. See the procedure below to see how it works.

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application for c#. ps1

Step 2

Add a picture box, a timer and two buttons inside the form. Then, do the form just like shown below. ps2

Step 3

Press F7 to open the code editor. In the code editor, declare a string array and an integer that equals to zero.
  1.  
  2. string[] pics = new string[] { "meme1.jpg", "meme2.jpg", "meme3.jpg", "meme4.jpg", "meme5.jpg" };
  3. int i = 0;

Step 4

Double click the form and do the following code for placing the first image in the picture box in the first load of the form.
  1.  
  2. pictureBox1.Image = Image.FromFile(Application .StartupPath + "//images//" + pics[0]);

Step 5

Write the following codes for the slide show of pictures when timer is start.
  1.  
  2. private void timer1_Tick(object sender, EventArgs e)
  3. {
  4. //'Set this formula to increment i by 1
  5. i += 1;
  6.  
  7. //'Set a validation of pictures
  8. if(pics.Length == i)
  9. {
  10. i = 0;
  11. }
  12.  
  13. //'Set to Load the image.
  14. pictureBox1.Image = Image.FromFile(Application.StartupPath + "//images//" + pics[i]);
  15. }

Step 6

Write the following code for the next button
  1.  
  2. private void button2_Click(object sender, EventArgs e)
  3. {
  4. //'Disable timer to prevent the next image from loading..
  5. timer1.Enabled = false;
  6.  
  7.  
  8. //'Set this formula to increment i by 1
  9. i += 1;
  10.  
  11.  
  12. //'Set a validation of pictures
  13. if( pics.Length == i)
  14. {
  15. i = 0;
  16. }
  17.  
  18. //'Set to Load the image.
  19. pictureBox1.Image = Image.FromFile(Application.StartupPath + "//images//" + pics[i]);
  20.  
  21.  
  22. //'Re-Enable timer to resets the image loads in 5 seconds..
  23. timer1.Enabled = true;
  24. timer1.Interval = 5000;
  25. }

Step 7

Write the following code for the previous button.
  1.  
  2. private void button1_Click(object sender, EventArgs e)
  3. {
  4. //'Disable timer to prevent the next image from loading..
  5. timer1.Enabled = false;
  6.  
  7.  
  8. //'Set this formula to increment i by 1
  9. i -= 1;
  10.  
  11.  
  12. //'Set a validation of pictures
  13. if (pics.Length == i)
  14. {
  15. i = 0;
  16.  
  17. }
  18.  
  19. //'Set to Load the image.
  20. pictureBox1.Image = Image.FromFile(Application.StartupPath + "//images//" + pics[i]);
  21.  
  22.  
  23. //'Re-Enable timer to resets the image loads in 5 seconds..
  24. timer1.Enabled = true;
  25. timer1.Interval = 5000;
  26. }
Note : The location of pictures is in the bin folder of the project. The complete source code is included. You can download it and run it on your computer. For any questions about this article. You can contact me @ Email – jannopalacios@gmail.com Mobile No. – 09305235027 – TNT Or feel fre

Add new comment