Subscribe to Subscribers
Talk to Webmaster Tony John

Resources » .NET programming » General

SlideShow Example in the WindowsApplication


Posted Date:     Category: General    
Author: Member Level: Gold    Points: 25


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.





Did you like this resource? Share it with your friends and show your love!


Responses to "SlideShow Example in the WindowsApplication"
Author: ramakrishna    02 Sep 2012Member Level: Bronze   Points : 0
how you get pos there where shoul i write pos and director.getfiles


Author: RayalaHariKishore    02 Sep 2012Member 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.



Feedbacks      

Post Comment:




  • 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Working with combobox
    Previous Resource: Treeview Control in WindowsForms Application
    Return to Resources
    Post New Resource
    Category: General


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.