Here'ssome sample VB.NET code to get you started. Drop a Toolstrip and
FolderBrowseDialog control on your form. Drop a Panel control and
set its Dock property to Fill and AutoScroll to True. Hope it
helps...
Public Class Form1
Private supportedExt() As String = {".BMP", ".JPG", ".JPEG", ".PNG", ".GIF", ".TIF", ".TIFF", ".EMF", ".WMF", ".ICO"}
Dim mPictures As New List(Of PictureBox)
Dim mZoom As Integer = 5
Public Sub SetFolder(ByVal path As String)
' Remove old pictureboxes
For Each pic As PictureBox In mPictures
Me.Panel1.Controls.Remove(pic)
pic.Dispose()
Next
mPictures.Clear()
' Read folder for new pictures
Dim files() As String = System.IO.Directory.GetFiles(path)
For Each file As String In files
Dim ext As String = System.IO.Path.GetExtension(file).ToUpper
If Array.IndexOf(supportedExt, ext) >= 0 Then
Try
Dim pic As New PictureBox
pic.Image = Bitmap.FromFile(file)
pic.SizeMode = PictureBoxSizeMode.Zoom
mPictures.Add(pic)
Me.Panel1.Controls.Add(pic)
Catch ex As Exception
Debug.Print(ex.Message)
End Try
End If
Next
arrangeView()
End Sub
Public Property Zoom() As Integer
Get
Return mZoom
End Get
Set(ByVal value As Integer)
If value > 0 Then mZoom = value
arrangeView()
End Set
End Property
Private Sub arrangeView()
' Calculate picture width and make aspect 3:4
Dim w As Integer = Me.Panel1.ClientSize.Width \ mZoom
Dim h As Integer = 4 * w \ 3
Dim ix As Integer = 0
Me.Panel1.AutoScrollPosition = New Point(0, 0)
Me.Panel1.SuspendLayout()
For hx As Integer = 0 To 99999 Step h
For wx As Integer = 0 To mZoom - 1
If ix >= mPictures.Count Then GoTo quit
With mPictures(ix)
.Left = wx * w
.Top = hx
.Width = w
.Height = h
ix += 1
End With
Next
Next
quit:
Me.Panel1.ResumeLayout()
End Sub
Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ResizeEnd
arrangeView()
End Sub
Private Sub btnZoomUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZoomUp.Click
Zoom = Zoom - 1
End Sub
Private Sub btnZoomDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZoomDown.Click
Zoom = Zoom + 1
End Sub
Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
If FolderBrowserDialog1.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
SetFolder(FolderBrowserDialog1.SelectedPath)
End If
End Sub
End Class