Lo que necesito hacer es crear un picturebox en el cual debo cargar varias imágenes y con botones de "Anterior" y "Siguiente" avanzar o retroceder en las imágenes, según sea el caso. Espero me puedan ayudar con eso.
Es muy sencillo, indexa las imágenes por ejemplo en un diccionario, y las cargas.
[youtube=640,360]http://www.youtube.com/watch?v=PJMIri5WSi4&feature=youtu.be[/youtube]
Source:
Public Class Form1
Dim ImageList As New Dictionary(Of Int32, String)
Dim ImageIndex As Int32 = 0
Dim TotalImages As Int32 = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Load_ImageList()
End Sub
' Botón "Anterior"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Not ImageIndex = 1 Then
ImageIndex -= 1
PictureBox1.BackgroundImage = Image.FromFile(ImageList.Item(ImageIndex))
End If
End Sub
' Botón "Siguiente"
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If Not ImageIndex = TotalImages Then
ImageIndex += 1
PictureBox1.BackgroundImage = Image.FromFile(ImageList.Item(ImageIndex))
End If
End Sub
Private Sub Load_ImageList()
ImageList.Add(1, "F:\Customización\Wallpapers\Animated\[AnimePaper]wallpapers_Bleach_Cilou(1.33)_1280x960_64991.jpg")
ImageList.Add(2, "F:\Customización\Wallpapers\Animated\0f61391cfd811f6cf57cf74b9fb00211.jpg")
ImageList.Add(3, "F:\Customización\Wallpapers\Animated\dragon_ball_z_broly_1771x1154_wallpaper_Wallpaper_1920x1440_www.wall321.com.jpg")
ImageList.Add(4, "F:\Customización\Wallpapers\Girls (Fantasy)\2.jpg")
ImageList.Add(5, "F:\Customización\Wallpapers\Girls (Fantasy)\7k982aivf38npdom4ol22653m15074a52c3a33c.jpg")
TotalImages = ImageList.Count
End Sub
End Class
bueno, eso es, aunque te has vuelto algo loco por el imagelist, realmente me parece mas sencillo con list of bitmap y bitmap.fromfile().
Cita de: ABDERRAMAH en 30 Abril 2013, 12:24 PMrealmente me parece mas sencillo con list of bitmap y bitmap.fromfile().
Tu eres el que está acostumbrado a trabajar con imágenes :P
Saludos!
yo lo haría así
Public imagestr As String() = {"imgs/img01.jpg", "imgs/img02.png", "imgs/img03.jpg", "c:/undir/imgs/img04.png"}
Private imgs As New List(Of Bitmap)
Private priv_index As Integer = 0
'utilizo una propiedad, de esta manera cuando cambie "index" la imágen
'se sitúa automáticamente en el picturebox
Public Property index As Integer
Get
Return Me.priv_index
End Get
Set(value As Integer)
If value < 0 Then
If imgs.Count > 0 Then
value = imgs.Count - 1
End If
ElseIf value >= imgs.Count Then
value = 0
End If
Me.priv_index = value
try
Me.picturebox1.image = imgs(Me.priv_index)
catch ex as exception
' no hay imágen !
end
End Set
End Property
' load imagelist lee un bitmap por cada texto en imagestr
' y lo memoriza en imgs
Public Sub load_imagelist()
imgs.Clear()
Dim tmp As Bitmap
For Each s As String In Me.imagestr
Try
tmp = Bitmap.FromFile(s)
Me.imgs.Add(tmp)
Catch ex As Exception
' no se encuentra el archivo
' ¿notificar al usuario?
End Try
Next
Me.index = 0
End Sub