SlideShow Example in the WindowsApplication


Here is the example of how to use the picture control and timer control. This is basic example for displaying the different pictures in the PictureBox as slideshow. And here we can manage it manually the time interval of the slideshow and also provided the previous and next buttons which will change the pictures.

Working with PictureBox control, ListBox, ComboBox and Timer control.
Here is the example of how to use the picture control and timer control. This is basic example for displaying the different pictures in the PictureBox as slideshow. And here we can manage it manually the time interval of the slideshow and also provided the previous and next buttons which will change the pictures.

Steps to do:

1) Create a new form and take the picturebox, listbox and button controls and one timer control.
2) And place it as below form.

3) Here ListBox is used for getting all the files (means pictures) from one folder and lists in it. For this we can see below code

  string[] img = Directory.GetFiles("C:\\Users\\Public\\Pictures\\Sample Pictures","*.*");
listBox1.Items.AddRange(img);


First line of code will get all the images of any type in the folder and then in the second line we are binding the files to the ListBox control.
4) Use ComboBox for the intervals. Like for how many seconds the image will change in the picturebox automatically.
For this you can give 1-10 statically (RAD way or Code way) .
5) Now we are having three buttons one for previous and other is next, SlideShow.
6) Previous Button will show the image previously shown (means before current image) here it checks that is the previous image present it shows otherwise the previous button will be disabled.

private void button1_Click(object sender, EventArgs e)
{
pos--;
if (pos < listBox1.Items.Count - 1)
{
button2.Enabled = true;
}
listBox1.SelectedIndex = pos;
if (pos == 0)
button1.Enabled = false;
}


First we are decrementing the position of the image in the listbox. If it is the first image we are disabling the button otherwise we are enabling the button.
7) Next button is also same just here we are incrementing.

private void button2_Click(object sender, EventArgs e)
{
pos++;
if (pos > 0)
button1.Enabled = true;
listBox1.SelectedIndex = pos;
if (pos == listBox1.Items.Count - 1)
button2.Enabled = false;
}


8) SlideShow button.

private void button3_Click(object sender, EventArgs e)
{
if (button3.Text == "SlideShow")
{
button3.Text = "Stop Show";
timer1.Interval = int.Parse(comboBox1.Text) * 1000;
timer1.Start();
}
else {
button3.Text = "SlideShow";
timer1.Stop();
}
}


Here we are checking if the text or value of the button is slideshow or not if it is we are changing the text to stop show and activating the timer to change image automatically at particular interval of time which is defined in the combobox 1-10. An if text is stop show then we are stoping the timer to stop showing images and changing text to slideshow which is again clicked to show the images.


All my resources are focusing the freshers you check all of my resources weekly I will post a new resource mainly for freshers.


Comments

Author: ramakrishna02 Sep 2012 Member Level: Bronze   Points : 0

how you get pos there where shoul i write pos and director.getfiles

Author: RayalaHariKishore02 Sep 2012 Member Level: Gold   Points : 0

hi,

that is globally declared variable. you didn't check the attachments check that once. if any clarifications needed revert here.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: