Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How we can create Slide show of images in Window Form.

Author: DevASP
Download Source Code : 586_slideshow.zip

This article is about how you can create slide show of images in your window application.

Steps you will do. 

Start visual studio and create a new window application. 

Place a text box on the form and set its following properties.

 

 

Text = “” 

Name = TextBox1 

Now place four button controls on the form and set their following properties as below.

 

 

First button control

 

Text = Browse

Font = Arial, 12pt, style=Bold

FontColor = ControlText

BackColor = Control

 

 

Second button control

 

Text = AddToList

Font = Arial, 12pt, style=Bold

FontColor = ControlText

BackColor = Control

 

 

Third button control

 

Text = SlideShow

Font = Arial, 12pt, style=Bold

FontColor = ControlText

BackColor = Control

 

 

Fourth button control

 

Text = Exit

Font = Arial, 12pt, style=Bold

FontColor = ControlText

BackColor = Control

 

Place a list box control on the form.

Place a picture box control on the form and set its following properties.

 

Name = PictureBox1 

BorderStyle = Fixed3D              

 

Now place an Open File Dialog control on the form. 

Open the code window of your form and import the following namespace and declare the following variable.

 

 

Imports System.threading  

Dim bn As Boolean

Dim pb1 As New PictureBox 

 

Write the following code in the click event of the first button to browse the image file.

 

 

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

            TextBox1.Text = OpenFileDialog1.FileName

        End If

 

Write following code in the TextChanged event of the text box.

 

 

PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage 

  PictureBox1.Image = Image.FromFile(TextBox1.Text)

 

Write the following code in the click event of the second button to insert the selected file into the list box.

 

 

If TextBox1.TextLength <= 0 Then

 

 

MessageBox.Show("PleaseSelect a file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button3)

   

Exit Sub

 

End If

  ListBox1.Items.Add(TextBox1.Text)

 

 

Write the following code in the SelectedIndexChanged event of the list box to show the selected image in the picture box.

 

PictureBox1.Image = Image.FromFile(ListBox1.SelectedItem)

 Write the following code in the click event of the exit button to exit from the application.

 

Application.Exit(? 

Now the actual work is here to slide show the images.

Make a sub  procedure as below.

 

 

Sub shows()

        Dim k, s As String

        Dim i, j, m As Integer

   For i = 0 To ListBox1.Items.Count - 1

            k = ListBox1.Items.Item(i)

            s = k

            pb1.Image = Image.FromFile(s)

            Thread.Sleep(3000)

        Next

        Exit Sub

 

    End Sub

 

Write the following code in the click event of the third button to make the slide show of selected images.

 

 

If ListBox1.Items.Count = 0 Then

      MessageBox.Show("Please insert atleast one image", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button3)

            Button1.Focus()

            Exit Sub

        End If

        Dim crux As New Form

        crux.WindowState = FormWindowState.Maximized

        crux.Size = New Size(20, 20)

        crux.MaximizeBox = False

        crux.MinimizeBox = False

        crux.BackColor = Color.Black

        crux.Text = "Dilip's SlideShowMaker"

        pb1.Dock = DockStyle.Fill

        pb1.BackColor = Color.Black

        pb1.Size = New Size(30, 30)

        pb1.SizeMode = PictureBoxSizeMode.StretchImage

        pb1.BorderStyle = BorderStyle.Fixed3D

        crux.Controls.Add(pb1)

        crux.Show()

        Me.Hide()

        Dim cbz As New Thread(AddressOf shows)

        cbz.Start()

 

 

 

False the following Boolean variable in the load event of the form as below. 

 

  bn = False
 

Run your application and select the images to see the slide show of images.

Article Comments
I am very happy for these coding

Posted on 8/24/2006 3:23:18 AM by saji

I am very very happy for these codings
Thanks alot 4 it,go ahead help other in this way.

Posted on 11/23/2007 3:17:58 PM by Roopak

I really pleased to get this code.

Posted on 12/19/2007 2:02:54 AM by Vorleak

I need to make a slide show using c#.net in web application with the images(image URL) stored in the database(sqkserver2000) .. need help

Posted on 1/4/2008 2:11:12 AM by stephen

this code is not running
and creating a error.
the error is wrong path.

Posted on 2/4/2008 11:46:03 PM by babita

hi
i really pleased to get this code,but i dont have knowledge of vb i want code in c# can u help me as soon as possible.
thanks.

Posted on 7/10/2008 7:55:26 AM by san

How to create slideshow of jpeg pictures using c# windows application using picturebox, imagelist and timer controls..

Reply soon..

Posted on 6/24/2010 9:24:24 AM by Rajesh

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to move object on window form.

Disclaimer - Privacy
© 2002-2017 DevASP.net