Question button popup with multiple thumbnails

ud2008

Well-known member
Joined
Jul 5, 2010
Messages
148
Programming Experience
Beginner
Maybe the title isn't very clear on what I try to do, but here's the explanation.

First I use vs 2010.

I have a form and a button, the button is to change the form background image.
When I click the button I want a popup to appear with 3 or 4 columns of thumbnails to chose from.

But the thing is, don't know how to do this.

Anyone an idea?
Is there an third party tool for it?

Thanks.
 
A "popup" is just a form. Create an appropriate form and call ShowDialog. You might have four PictureBoxes on the form and handle the Click event of each one to set a property appropriately. The calling form can then get the value of that property to determine which Image was selected and respond accordingly.
 
Thanks for the reply.

But I don't think it's what I want.

Here is a picture of what I am looking for:

The thumbnail images are in a folder and are loaded when the button is clicked (all the images).

Hope someone has an idea how to get this working.
 
What you're showing is a dialog where there are pictureboxes showing the images just as jmcilhinney suggested.

-----

I'll give you a little help to get you started.

1. Create a UserControl named something appropriate (I named mine ThumbControl in my example)
2. Add a PictureBox to the UserControl, set its name to PictureBox and set its dock property to Top
3. Add a Label to the UserControl, set its name to Label and set its dock property to Bottom

4. Add another form to your project (Named GalleryDialog in the example)
5. Add a FlowLayoutPanel to your form and set AutoScroll to True and Dock to Fill

Here's the code I used to show all of the images in the directory:

VB.NET:
Imports System.IO

Public Class GalleryDialog

    Private Sub GalleryDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles MyBase.Load

        ImagesFlowLayoutPanel.Controls.Clear()

        Dim di = New DirectoryInfo("C:\Temp\Images")
        Dim exts As New List(Of String) From {"*.jpg", "*.gif", "*.png"}

        Dim fiList As New List(Of FileInfo)
        For Each searchPattern In exts
            fiList.AddRange(di.GetFiles(searchPattern, SearchOption.TopDirectoryOnly))
        Next

        For Each fi In fiList
            Dim tc As New ThumbControl
            With tc
                .Height = 150
                .Width = 150
                .PictureBox.Height = 125
                .PictureBox.Width = 125
                .PictureBox.SizeMode = PictureBoxSizeMode.Zoom
                .PictureBox.ImageLocation = fi.FullName
                .Label.Text = fi.Name
                ImagesFlowLayoutPanel.Controls.Add(tc)
            End With
        Next

    End Sub
End Class

Now you'll just need to handle the click event for the ThumbControl.
 
Last edited:
thanks, I can use most of the code, but I have a small question, shouldn't ThumbControl be UserControl? Because it is not declared or what do I miss?
 
the only question I have with this one.

How can I click on (select picturebox) a picture (from all the pictures) and create an event?

Thanks
 
thanks, I can use most of the code, but I have a small question, shouldn't ThumbControl be UserControl? Because it is not declared or what do I miss?

It's ThumbControl in my code because that's what I named the UserControl.

ud2008 said:
How can I click on (select picturebox) a picture (from all the pictures) and create an event?

Use AddHandler for each ThumbControl you're adding to the FlowLayoutPanel.

Here I'm adding a handler for if someone clicks on the PictureBox in the UserControl.

VB.NET:
AddHandler tc.PictureBox.Click, AddressOf ThumbControl_Click
 
Back
Top