Slide Show Application Using C#

Download Zip File Here

In this article I demonstration on how to develope slide show application using C#.

11)    Open visual studio 2012.


22)    Select file -> New ->Project         
3)    Select language as “visual c#” and  template as “Windows Forms Application”,give appropritate name,I give name as SlideShowApp .select Location as click on ok .
44)    Place the Panel on the form and set the dock property as right.
55)    Now place the picturebox and set dock property as fill
66)    Now design a   form as following.




77)    Drag and drop FolderBrowserDiaglog and Timer control in the form.they will appear at bottom .go to timer control property and set Interval=3000.

88)    Under the properties of next(>) ,previous(<)  and Slide Show button set Enable property is False.so by default they should be disable state .
99)    Before you must need to import namespace System.IO


10)                       Then write the following code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace SlideShowApp
{
    public partial class Form1 : Form
    {
        string Dirpath;
        int imgindex;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 1; i < 10; i++)
            {
                comboBox1.Items.Add(i);
                comboBox1.SelectedIndex = 0;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult dr = folderBrowserDialog1.ShowDialog();
            if (dr != DialogResult.Cancel)
            {
                listBox1.Items.Clear();
                Dirpath = folderBrowserDialog1.SelectedPath;
                string[] files = Directory.GetFiles(Dirpath, "*.Jpg");
                foreach (string file in files)
                {
                    int pos = file.LastIndexOf("||");
                    string FName = file.Substring(pos + 1);
                    listBox1.Items.Add(FName);
                }
                listBox1.SelectedIndex = imgindex = 0;
                btnprev.Enabled = true;
                btnnext.Enabled = btnshow.Enabled = true;
            }
        }

        private void btnshow_Click(object sender, EventArgs e)
        {
            if (btnshow.Text == "Slide Show")
            {
                btnshow.Text = "stop show";
                timer1.Interval = int.Parse(comboBox1.Text) * 1000;
                timer1.Start();
            }
            else
            {
                timer1.Stop();
                btnshow.Text = "Slide Show";
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            pictureBox1.ImageLocation = listBox1.SelectedItem.ToString ();
           // pictureBox1.ImageLocation = Dirpath + "\\" + listBox1.SelectedItem;
        }

        private void btnprev_Click(object sender, EventArgs e)
        {
            if (imgindex > 0)
            {
                imgindex -= 1;
                if(imgindex ==0)
                {
                    btnprev .Enabled=false;
                }
                if (imgindex < listBox1.Items.Count - 1)
                    btnnext.Enabled = true;
                listBox1.SelectedIndex = imgindex;
            }
        }

        private void btnnext_Click(object sender, EventArgs e)
        {
            if (imgindex < listBox1.Items.Count - 1)
            {
                imgindex += 1;
                if (imgindex == listBox1.Items.Count - 1)
                    btnnext.Enabled = false;
            if (imgindex > 0)
                btnprev.Enabled = true;                
                listBox1.SelectedIndex = imgindex;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            btnnext.PerformClick();
        }
    }
}
11)now save the application.run the application. Click on  load images browse the folder and select images folder.click on ok.click on (>)(<) button and check previous and next is working or not.click on start show  show is started  and if you want to stop the show the click on stop show.

12)i show video demonstration  also how it works.
Hope you like my artical.

If you want to more artical then visit my blog



or any query  frankly mail me dotnetbyabhipatil@gmail.com

Previous
Next Post »