In fact, here's an example I've not together to illustrate the point. You'll need a form with two picture boxes on it, one called picDisplay and the other picLoad. You'll also need to add a reference to the Microsoft Scripting Runtime library. Finally you'll need a horizontal scroll bar
[tt]
Option Explicit
Private Type PictureDisp
width As Long
positionleft As Long
filename As String
End Type
Private myPictures() As PictureDisp
Private ScrollRatio As Double
Private Sub Form_Load()
picLoader.Visible = False
picLoader.ScaleMode = vbPixels
picDisplay.ScaleMode = vbPixels
picDisplay.AutoRedraw = True
Form1.ScaleMode = vbPixels
GetImages "c:\downloads\jpegs" ' You would choose your image folder here
End Sub
Private Sub Form_Resize()
picDisplay.Move 0, 0, Form1.ScaleWidth, Form1.ScaleHeight - 16
HScroll1.Move 0, picDisplay.ScaleHeight, Form1.ScaleWidth, 16
Form1.Refresh
DisplayImages
End Sub
Private Sub HScroll1_Change()
DisplayImages
End Sub
Private Sub GetImages(strSourceFolder As String)
Dim filename As File
Dim myPicture As Picture
Dim lp As Long
Dim FullWidth As Long
With New FileSystemObject
For Each filename In .GetFolder(strSourceFolder).Files
If filename.Type = "JPEG Image" Then
Set picLoader = LoadPicture(filename.Path)
With picLoader
ReDim Preserve myPictures(lp)
myPictures(lp).width = .width + 16 ' the 16 is to put a gap between the images when displayed
myPictures(lp).positionleft = FullWidth
FullWidth = FullWidth + myPictures(lp).width
myPictures(lp).filename = filename.Path
End With
lp = lp + 1
End If
Next
End With
HScroll1.Min = 0
HScroll1.Max = 32767 'max it can be
ScrollRatio = FullWidth / HScroll1.Max ' we may well have a maximum theoretical width greater than Hscroll can deal with, so use a ratio
HScroll1.SmallChange = 32 ' pixels
HScroll1.LargeChange = 320 ' pixels
picDisplay.Cls
End Sub
Private Sub DisplayImages()
Dim lp As Long
Dim InView As Boolean
Dim LeftPosition As Long
Dim RightPosition As Long
picDisplay.Cls
For lp = LBound(myPictures) To UBound(myPictures)
' Here's where we verify whether an image is in our viewport before bothering to either load or display it
InView = False
LeftPosition = myPictures(lp).positionleft - HScroll1 * ScrollRatio
RightPosition = myPictures(lp).positionleft + myPictures(lp).width - HScroll1 * ScrollRatio
If LeftPosition >= 0 And LeftPosition < picDisplay.width Then
InView = True
ElseIf LeftPosition < 0 And RightPosition > 0 Then
InView = True
End If
' If it is in view, then load and display at the appropriate position in the viewport
If InView Then
Set picLoader = LoadPicture(myPictures(lp).filename)
picDisplay.PaintPicture picLoader, myPictures(lp).positionleft - HScroll1 * ScrollRatio, 0
End If
Next
End Sub