How make image file zoom on scrren when the user double-clicks the file name in a listbox?

I have a listbox that is populated with file names that exist in a specific directory.

The onopen event code of the form that puts them there is:

Private Sub Form_Open(Cancel As Integer)

    With Me.ListImageFiles 'the name of your listbox
        .RowSource = PopListBox(Me.txtClientImageFolderDataPath)   ' You can leave the ext. out to show all files
        .RowSourceType = "value list"
    End With

    Me.cmdCloseForm.SetFocus

End Sub

Open in new window


Also in the form code is this:

Function PopListBox(strPath As String, Optional FileExtension As String) As String

    Dim MyFso As Object
    Dim MainDir As Object
    Dim MyFile As Object
    Dim LstItems As String, FileProp As String
    Dim NameLength As Integer, InitialNameLength As Integer, TypeLength As Integer, InitialTypeLength As Integer
    Dim x As Integer, y As Integer
    Dim NameSep As Integer, TypeSep As Integer
    Dim Placer As Variant
    On Error Resume Next
    Set MyFso = CreateObject("scripting.FileSystemObject")
    Set MainDir = MyFso.GetFolder(strPath)
    InitialNameLength = 1
    InitialTypeLength = 1
    For Each MyFile In MainDir.Files ' all this in side this loop is to help try and format the columns a bit more uniformly.
        NameLength = Len(MyFile.Name)
        x = IIf(NameLength > InitialNameLength, NameLength, InitialNameLength)
        InitialNameLength = x
        
        TypeLength = Len(MyFile.Type)
        y = IIf(TypeLength > InitialTypeLength, TypeLength, InitialTypeLength)
        InitialTypeLength = y
    Next
    For Each MyFile In MainDir.Files
    Placer = InStr(1, MyFile.Name, ".") - 1
    NameSep = x - Len(MyFile.Name) + 4
    TypeSep = y - Len(MyFile.Type) + 4
    
    If Mid(MyFile.Name, InStr(1, MyFile.Name, ".") + 1) = FileExtension Then
        FileProp = Mid(MyFile.Name, 1, Placer) '& String(NameSep, "_") '& MyFile.Type & String(TypeSep, "_") & MyFile.DateCreated
        LstItems = LstItems & FileProp & ";"
    ElseIf FileExtension = "" Then
        FileProp = Mid(MyFile.Name, 1, Placer) '& String(NameSep, "_") '& MyFile.Type & String(TypeSep, "_") & MyFile.DateCreated
        LstItems = LstItems & FileProp & ";"
    End If
    
    Next
    Debug.Print LstItems
    'Clean up
    Set MyFso = Nothing
    Set MainDir = Nothing
    PopListBox = UCase(LstItems)
    
End Function

Open in new window


Now what I want to do is allow the user to double-click on a file name in the listbox and have that image appear "zoomed" on the user's screen like an image preview would.  Can this be done and how?

--Steve
SteveL13Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MlandaTCommented:
1 -  Create a new form (name it ImageForm1) and add an image/picture control to this form (suppose the image control is Image1). Format it so that the image control is occupying a large enough portion of the screen.

2  - Create a function in this form, call it perhaps
Public Sub LoadImage(FullImagePathAs String)
     Image1.Picture = LoadPicture(FullImagePath)
End Sub

Open in new window


3  - In the form with your listbox, add a function to handle the double click event
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
        If ListBox1.ListIndex <> -1 Then
                'ImageForm1.LoadImage(ListBox1.Value)
                ImageForm1.LoadImage(ListBox1.List(ListBox1.ListIndex, 1))
                ImageForm1.Show
        end If
End Sub

Open in new window

SteveL13Author Commented:
I get a compile error.  It doesn't seem to like the line:

ImageForm1.LoadImage(ListBox1.List(ListBox1.ListIndex, 1))

Especially the .List part of it.
SteveL13Author Commented:
I'm starting over.  Here is my code now to display the image files in the listbox:

Private Sub Form_Current()

Dim strFileName As String
Dim strPath As String

    If IsNull(Me.txtSiteImageFolder) Then
        Exit Sub
    End If

    strPath = Me.txtSiteImageFolder

    If Right$(strPath, 1) <> "\" Then strPath = strPath & "\"

    Me.ListImageFiles.RowSource = ""
            
    strFileName = Dir$(strPath, vbNormal)    ' Retrieve the first entry.

    Do Until strFileName = ""

        strFileName = Dir
        
        If Right(strFileName, 3) = "jpg" Then
            Me.ListImageFiles.AddItem strFileName
        End If

    Loop

End Sub

Open in new window


And what I want to do is allow the user to double-click on a file name in the listbox and have that image appear "zoomed" on the user's screen like an image preview would.  Can this be done and how?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Jeffrey CoachmanMIS LiasonCommented:
appear "zoomed" on the user's screen
Zoomed "where" specifically on the screen?
On the current form?, or a new form?
 (both could be considered to be on the users "screen")
Using the current form will be problematic because of the limited real estate available on the current form.

If it were me, I would go with the pop-up form approach.
Again, ...going with the sample I posted for you a while ago, this approach works well...

JeffCoachman
Database89.mdb

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeffrey CoachmanMIS LiasonCommented:
So my solution worked out well for you?

I was not sure if "Zoomed" just meant "bigger", ...or a more complicated "dynamic zoom", like you get on Amazon.com.

Jeff
SteveL13Author Commented:
Yes,

Your database example was what I needed.
Jeffrey CoachmanMIS LiasonCommented:
ok
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.