Hallo!
Eigentlich arbeitet man mit einer festen Zahl von Pictureboxen,
denen Bilder variabel zugewiesen werden.
Hier ein Beispiel mit komprimierter Ladung der Bilddaten in
MemoryStreams (per Backgroundworker).
Bei Bedarf erfolgt die Bildauswahl über eine Trackbar.
(Eine Progressbar zur Anzeige des Ladefortschritts kann eingebaut werden.)
Public Class frmThumbsII
Dim mnuMain As New MenuStrip With {.Parent = Me}
Dim fbd As New FolderBrowserDialog With _
{.Description = "Ordner mit Bilddateien", _
.ShowNewFolderButton = False}
Dim pb_list As New List(Of PictureBox)
Dim pics As New List(Of IO.MemoryStream)
Dim WithEvents trbPics As New TrackBar With _
{.Parent = Me, .Dock = DockStyle.Bottom}
Dim WithEvents bgw As New System.ComponentModel.BackgroundWorker
Dim PicPath As String
Private Sub frmThumbsII_Load(sender As System.Object, _
e As System.EventArgs) Handles MyBase.Load
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
Dim th_Width As Integer = 150
Me.Size = New Size(th_Width * 4 + 10, th_Width * 4 + 130)
trbPics.Height = 50 : trbPics.Top = Me.Height - 80
mnuMain.Items.Add("Bilder laden", Nothing, AddressOf mnuload_click)
Dim z As Integer
For i As Integer = 0 To 3
For k As Integer = 0 To 3
z += 1
Dim pb As New PictureBox With _
{.Parent = Me, .Top = i * th_Width + 50, .Left = k * _
th_Width, _
.Width = th_Width, .Height = th_Width, _
.BorderStyle = BorderStyle.FixedSingle,
.SizeMode = PictureBoxSizeMode.Zoom, .Tag = z}
AddHandler pb.Click, AddressOf pbox_click
pb_list.Add(pb)
Next k
Next i
End Sub
Private Sub mnuload_click(ByVal sender As Object, e As EventArgs)
With fbd
If .ShowDialog = Windows.Forms.DialogResult.Cancel Then Exit Sub
Me.UseWaitCursor = True
trbPics.Visible = False
Me.Refresh()
PicPath = .SelectedPath
bgw.RunWorkerAsync()
End With
End Sub
Private Sub pbox_click(ByVal sender As Object, e As EventArgs)
Dim pb As PictureBox = CType(sender, PictureBox)
Dim z As Integer = CInt(pb.Tag)
MsgBox("Bild " & CStr(z) & " ist angeclickt")
End Sub
Private Sub trbPics_ValueChanged(sender As Object, _
e As System.EventArgs) Handles trbPics.ValueChanged
Static IsBusy As Boolean
If IsBusy Then Exit Sub
IsBusy = True
For i As Integer = 0 To pb_list.Count - 1
With pb_list(i)
If .Image IsNot Nothing Then
.Image = Nothing : .Tag = -1
End If
Dim index As Integer = trbPics.Value + i
If index < pics.Count Then
.Image = Image.FromStream(pics(index))
.Tag = trbPics.Value + i
End If
.Refresh()
End With
Next i
IsBusy = False
End Sub
Private Sub bgw_DoWork(sender As Object, _
e As System.ComponentModel.DoWorkEventArgs) Handles bgw.DoWork
pics.Clear()
For Each file As String In My.Computer.FileSystem.GetFiles(PicPath, _
FileIO.SearchOption.SearchTopLevelOnly, "*.jpg")
Using fs As New IO.FileStream(file, IO.FileMode.Open, _
IO.FileAccess.Read)
Dim buffer(CInt(fs.Length - 1)) As Byte
fs.Read(buffer, 0, buffer.Length)
pics.Add(New IO.MemoryStream(buffer))
End Using
Next file
End Sub
Private Sub bgw_RunWorkerCompleted(sender As Object, _
e As System.ComponentModel.RunWorkerCompletedEventArgs) _
Handles bgw.RunWorkerCompleted
With trbPics
.Value = 0
.Visible = pics.Count > pb_list.Count
If .Visible Then .Maximum = pics.Count - pb_list.Count
.TickFrequency = Math.Max(1, pics.Count \ 10)
End With
Me.Text = CStr(pics.Count) & " JPEGs sind geladen"
trbPics_ValueChanged(Me, Nothing)
Me.UseWaitCursor = False
End Sub
End Class
Beitrag wurde zuletzt am 06.01.13 um 14:40:59 editiert. |