Knowing how to create a slide-show program using Microsoft Visual Basic.NET (VB.NET) can save you time when you need to show your pictures to friends and family. VB.NET is an object-oriented computer programming language used to design Windows applications. A slide show is used to display images while pausing a few seconds in between. In a few steps you will create a slide-show VB.NET project using a picture box, list box and a few buttons.
- Skill level:
Things you need
- Microsoft Visual Basic Express
Start Microsoft Visual Basic Express, click "New Project..." on the left pane of your screen, then select "Windows Forms Application." Click "OK."
Double click "Button" on the "Toolbox" pane to add a new button control. Add a second button. Double click "PictureBox" to add a new picture-box control.
Double click "ListBox" to add a list-box control. Double click "OpenFileDialog" to add the control to your project. Double click "Button1" to open the "Form1.vb"module.
Copy and paste the following code under "Button1_Click" to open the file dialogue Window and browse for images:
OpenFileDialog1.Multiselect = False
OpenFileDialog1.Filter = "Jpeg|*.jpg|Gif|*.gif|Jpeg|*.jpeg|Bitmap|*.bmp" OpenFileDialog1.RestoreDirectory = True OpenFileDialog1.Title = "Browse" If OpenFileDialog1.ShowDialog <> DialogResult.Cancel Then ListBox1.Items.Add(OpenFileDialog1.FileName) End If
Copy and paste the following code to create a new procedure to loop through the images and pause between them using a Thread:
Dim iCntr As Integer For iCntr = 0 To ListBox1.Items.Count - 1 pctrBx.Image = Image.FromFile(ListBox1.Items.Item(iCntr)) Thread.Sleep(3000) Next Exit Sub End Sub
Copy and paste the following code under "Public Class Form1" to declare two global variables:
Dim pctrBx As New PictureBox
Dim frmFrame As New Form
Click "Form1.vb" and double click "Button2." Copy and paste the following code to show the Form where the images are going to be displayed and also start the Thread:
If ListBox1.Items.Count <> 0 Then
frmFrame.Size = New Size(1000, 1000) frmFrame.BackColor = Color.Black frmFrame.Text = "Image Slideshow" pctrBx.Dock = DockStyle.Fill pctrBx.BackColor = Color.Black pctrBx.SizeMode = PictureBoxSizeMode.StretchImage pctrBx.BorderStyle = BorderStyle.Fixed3D frmFrame.Controls.Add(pctrBx) frmFrame.Show() Dim pause Thread As New Thread(AddressOf slideShow) pauseThread.Start() Else MsgBox("Please select an image") End If
Click "Form1.vb" and double click "ListBox1." Copy and paste the following code to add the selected item in the Listbox to the PictureBox control:
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureBox1.Image = Image.FromFile(ListBox1.SelectedItem)
Click the "Debug" menu then select "Start Debugging" to run your program. Click "Button1" to browse for images. Click "Button2" to start the slide show.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for