Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents iePicture As AxSHDocVw.AxWebBrowser
    Friend WithEvents cboFolders As System.Windows.Forms.ComboBox
    Friend WithEvents lstFiles As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.iePicture = New AxSHDocVw.AxWebBrowser()
        Me.cboFolders = New System.Windows.Forms.ComboBox()
        Me.lstFiles = New System.Windows.Forms.ListBox()
        CType(Me.iePicture, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'iePicture
        '
        Me.iePicture.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.iePicture.Enabled = True
        Me.iePicture.Location = New System.Drawing.Point(136, 40)
        Me.iePicture.OcxState = CType(resources.GetObject("iePicture.OcxState"), System.Windows.Forms.AxHost.State)
        Me.iePicture.Size = New System.Drawing.Size(312, 264)
        Me.iePicture.TabIndex = 0
        '
        'cboFolders
        '
        Me.cboFolders.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.cboFolders.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboFolders.Location = New System.Drawing.Point(8, 8)
        Me.cboFolders.Name = "cboFolders"
        Me.cboFolders.Size = New System.Drawing.Size(448, 21)
        Me.cboFolders.TabIndex = 1
        '
        'lstFiles
        '
        Me.lstFiles.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left)
        Me.lstFiles.IntegralHeight = False
        Me.lstFiles.Location = New System.Drawing.Point(8, 40)
        Me.lstFiles.Name = "lstFiles"
        Me.lstFiles.Size = New System.Drawing.Size(120, 264)
        Me.lstFiles.TabIndex = 2
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(464, 317)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lstFiles, Me.cboFolders, Me.iePicture})
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.iePicture, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' set the browser to a default page...
        iePicture.Navigate2("http://www.google.com/")

        ' get the pictures...
        Try

            ' create a connection to the service...
            Dim service As New PictureService.Service()

            ' get a list of the folders...
            Dim folderNames() As String
            folderNames = service.GetPictureFolders

            ' go through the list and add each name...
            Dim folderName As String
            For Each folderName In folderNames
                cboFolders.Items.Add(folderName)
            Next

        Catch ex As Exception
            HandleException(ex)
        End Try

    End Sub


    ' HandleException - handle a Web service exception...
    Private Function HandleException(ByVal e As Exception)

        ' loop through the inner exceptions...
        Do While Not e.InnerException Is Nothing
            e = e.InnerException
        Loop

        ' report the problem...
        MsgBox("An exception occured. " & e.Message)

    End Function


    Private Sub cboFolders_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboFolders.SelectedIndexChanged
        ' what folder did we select?
        Dim folderName As String = _
            cboFolders.Items(cboFolders.SelectedIndex)

        ' clear the files list...
        lstFiles.Items.Clear()

        ' connect to the service again and get the files back...
        Try

            ' connect...
            Dim service As New PictureService.Service()

            ' get the files back...
            Dim pictureList() As PictureService.PictureInfo
            pictureList = service.GetPicturesInFolder(folderName)

            ' add the pictures to the list...
            Dim pictureInfo As PictureService.PictureInfo
            For Each pictureInfo In pictureList

                ' just add the name...
                lstFiles.Items.Add(New PictureItem(pictureInfo))

            Next

        Catch ex As Exception
            HandleException(ex)
        End Try

    End Sub


    Private Sub lstFiles_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstFiles.SelectedIndexChanged
        ' get the pictureitem...
        Dim item As PictureItem = lstFiles.Items(lstFiles.SelectedIndex)
        If Not item Is Nothing Then

            ' tell ie to show the picture...
            iePicture.Navigate2(item.PictureInfo.URL)

        End If

    End Sub


End Class
