Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Public Class Form1

  Private Sub Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click
    Dim OpenFileDialog1 As New OpenFileDialog
    OpenFileDialog1.Filter = "Images (*.BMP;*.JPG;*.GIF,*.PNG,*.TIFF)|*.BMP;*.JPG;*.GIF;*.PNG;*.TIFF|" + "All files (*.*)|*.*"
    OpenFileDialog1.Multiselect = True
    OpenFileDialog1.Title = "Select Photos"

    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

      For Each file As String In OpenFileDialog1.FileNames
        Dim imgFilename As String = IO.Path.GetFileNameWithoutExtension(file)
        Dim img As New System.Drawing.Bitmap(file)
        Dim imgImage As Image = Image.FromFile(file)
        Dim imageControl As New PictureBox()

        imageControl.Height = 100
        imageControl.Width = 100
        Dim myCallback As New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
        Dim myBitmap As New Bitmap(file)
        Dim myThumbnail As Image = myBitmap.GetThumbnailImage(96, 96, myCallback, IntPtr.Zero)
        imageControl.Image = myThumbnail
        PhotoGallery.Controls.Add(imageControl)
      Next
    End If
  End Sub

  Public Function ThumbnailCallback() As Boolean
    Return False
  End Function

End Class
Posted
Updated 24-Dec-14 22:47pm
v4

out of curiosity, what type of object is photogallery. if this is a panel or other container object, you may have to set the coordinates of each picturebox. adding them in the way you have, will just place one picturebox on top of another.
 
Share this answer
 
Comments
terry.corridan 26-Dec-14 19:58pm    
Sorry. The PhotoGallery is a PictureBox, but it doesn't have to be. A ListView would be just as good. What I am trying to do is have a list of thumbnails displayed and be able to click and drag them so as to display them in a different order. Do you have any ideas that might help? Many thanks.
the edits below should create a vertical list of images. if you want columns and rows, it will take a bit more math work. I think the easiest way to go would be the listview. Using the edited code below will at least help us determine if the imageControl's images are different.

VB
Public Class Form1

  Private Sub Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click
    Dim OpenFileDialog1 As New OpenFileDialog
  
  'added code
    Dim curTop As Integer = 0

    OpenFileDialog1.Filter = "Images (*.BMP;*.JPG;*.GIF,*.PNG,*.TIFF)|*.BMP;*.JPG;*.GIF;*.PNG;*.TIFF|" + "All files (*.*)|*.*"
    OpenFileDialog1.Multiselect = True
    OpenFileDialog1.Title = "Select Photos"

    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

      For Each file As String In OpenFileDialog1.FileNames
        Dim imgFilename As String = IO.Path.GetFileNameWithoutExtension(file)
        Dim img As New System.Drawing.Bitmap(file)
        Dim imgImage As Image = Image.FromFile(file)
        Dim imageControl As New PictureBox()

        imageControl.Height = 100
        imageControl.Width = 100
        Dim myCallback As New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
        Dim myBitmap As New Bitmap(file)
        Dim myThumbnail As Image = myBitmap.GetThumbnailImage(96, 96, myCallback, IntPtr.Zero)
        imageControl.Image = myThumbnail
        imageControl.Top = curTop 'code added
        curTop += imageControl.Height 'code added
        PhotoGallery.Controls.Add(imageControl)
      Next
    End If
  End Sub

  Public Function ThumbnailCallback() As Boolean
    Return False
  End Function

End Class


Also on a note, Change PhotoGallery from a Picturebox to a Panel Control So that you can scroll through your thumbnails. Just Set the AutoScroll Property to true.
Alternatively Below will display the Thumbnails in multiple Columns and Rows.
VB
Private Sub Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click
    Dim OpenFileDialog1 As New OpenFileDialog
    Dim cols As Integer = (PhotoGallery.Width - (PhotoGallery.Width Mod 100)) / 100
    Dim curLeft As Integer = 0
    'added code
    Dim curTop As Integer = 0

    OpenFileDialog1.Filter = "Images (*.BMP;*.JPG;*.GIF,*.PNG,*.TIFF)|*.BMP;*.JPG;*.GIF;*.PNG;*.TIFF|" + "All files (*.*)|*.*"
    OpenFileDialog1.Multiselect = True
    OpenFileDialog1.Title = "Select Photos"

    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

        For Each file As String In OpenFileDialog1.FileNames
            Debug.Print(file)
            Dim imgFilename As String = IO.Path.GetFileNameWithoutExtension(file)
            Dim img As New System.Drawing.Bitmap(file)
            Dim imgImage As Image = Image.FromFile(file)
            Dim imageControl As New PictureBox()

            imageControl.Height = 100
            imageControl.Width = 100
            Dim myCallback As New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
            Dim myBitmap As New Bitmap(file)
            Dim myThumbnail As Image = myBitmap.GetThumbnailImage(96, 96, myCallback, IntPtr.Zero)
            If myThumbnail IsNot Nothing Then
                imageControl.Image = myThumbnail
            Else
                imageControl.BackgroundImage = myBitmap
                imageControl.BackgroundImageLayout = ImageLayout.Zoom
            End If
            imageControl.BackColor = Color.Black
            imageControl.Left = curLeft * 100
            imageControl.Top = curTop * 100
            curLeft += 1
            If curLeft >= cols Then
                curLeft = 0
                curTop += 1
            End If



            PhotoGallery.Controls.Add(imageControl)
        Next
    End If
End Sub

Public Function ThumbnailCallback() As Boolean
    Return False
End Function
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900