I started redesigning a picture viewer (of my grandchildren) after someone had asked a question about loading images. So I could distribute this app to friends and relatives I decided the best way to do it was to include a folder to be installed on their C: This way I could update the folder of pictures at anytime without changing the application. Right now I select either individual names or all the pictures from a combo box like this:
vb Code:
Private Sub cboSelectPicture_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboSelectPicture.SelectedIndexChanged Me.Refresh() Try Dim selectedName As String = Me.cboSelectPicture.Text ' Get and display pictures of only grandchild selected If selectedName <> "All Grandchildren" Then Dim imageFiles As String() = IO.Directory.GetFiles("C:\Pictures\", selectedName & "*.jpg") Dim images As New ArrayList For Each imageFile As String In imageFiles Select Case IO.Path.GetExtension(imageFile).ToLower() Case ".jpg", ".bmp", ".gif", ".png" images.Add(Image.FromFile(imageFile)) End Select Next imageFile Me.images = DirectCast(images.ToArray(GetType(Image)), Image()) ElseIf selectedName = "All Grandchildren" Then ' Get and display pictures of all grandchildren Dim imageFiles As String() = IO.Directory.GetFiles("C:\Pictures\", "*.jpg") Dim images As New ArrayList For Each imageFile As String In imageFiles Select Case IO.Path.GetExtension(imageFile).ToLower() Case ".jpg", ".bmp", ".gif", ".png" images.Add(Image.FromFile(imageFile)) End Select Next imageFile Me.images = DirectCast(images.ToArray(GetType(Image)), Image()) End If Catch ex As Exception MessageBox.Show("cboSelectPicture_SelectedIndexChanged: " & ex.ToString) End Try End Sub
Is there a more effective way of doing this or is this as good as it gets?


Reply With Quote