Its very easy to Create a VB 2008/2010 Picture Slide Show all you use is;a Timer, PictureBox, OpenFileDialogBox and a List Box.
You will
- Work with a Timer.
- Add Items to a listbox
- Remove a specific Item from a listbox
- Remove all items from a listbox(Clear)
- Using an OpenFileDialog box
- and working with MessageBox Results
Create a VB Form and in it, insert a Tab Controler with two tabs. One tab for the slide show, and the other tab for the settings of the slide show.
Below is a Table showing details of the Form and the Other Objects
Object | Property | Settings | Function |
Form | Name: Text: MaximiseBox: StartPosition: | frmSlide “Slide Show” False CenterScreen | Slide Show |
Timer | Name: Interval: | tmrPicTimer 1000 | Changes image after 1 second |
OpenFileDialog | Name: FileName: | OpenPic “ ” | Browse Computer for images |
TabControl | Name: TabPages: | mainTab tabShow, tabSettings | Multiple tabs in one form to avoid using many Forms |
PictureBox | Name: BorderStyle: SizeMode: | picSlideShow FixedSingle StretchImage | Show Images/Slides |
Button | Name: Text: | btnStart “Start” | Starts Show/Timer |
Button | Name: Text: | btnStop “Stop” | Stops Show/Timer |
Button | Name: Text: | btnExit “Exit” | Exits/Quits Application |
ListBox | Name: | lstPictures | List of Pictures Added by user |
Button | Name: Text: | btnAdd “Add” | Adds Images into lstPictures as items from Dialog box |
Button | Name: Text: | btnRemove “Remove” | Removes Selected Item/pic from lstPictures |
Button | Name: Text: | btnClear “Clear” | Clears all items/pictures from lstPictures |
Step 2: Code
Public Class Form1
Dim PicNum, Counter As Integer
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
tmrPicTimer.Enabled = True
tmrPicTimer.Start()
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
tmrPicTimer.Enabled = False
End Sub
Private Sub tmrPicTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrPicTimer.Tick
PicNum = lstPictures.Items.Count
If Counter < PicNum Then
picSlideShow.Image = Image.FromFile(lstPictures.Items.Item(Counter))
Counter = Counter + 1
Else
Counter = 0
picSlideShow.Image = Image.FromFile(lstPictures.Items.Item(Counter))
End If
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lstPictures.Items.Clear()
End Sub
Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
lstPictures.Items.RemoveAt(lstPictures.SelectedIndex)
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If OpenPic.ShowDialog() = Windows.Forms.DialogResult.OK Then
lstPictures.Items.Add(OpenPic.FileName)
End If
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
If MsgBox("Are you Sure you want to Quit?", MsgBoxStyle.YesNo, "Quit") = MsgBoxResult.Yes Then
Application.Exit()
End If
End Sub
End Class