Page 1 of 1

Pull pictures from Resources

Posted: Sat Jan 26, 2013 6:47 pm
by muttley1968
Hello i want to set a picturebox image from Resources but at random so i have
pic 1
pci 2
pic 3


and i want on load for it to randomly pic the picutre and set it as the picturebox image i have used this
code in my fist attempt but it does nothing i dont get any errors it just dosenot do a thing
Code: Select all
Public Class Main
    Private imgList As New List(Of Bitmap)
    Private Sub Main_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        imgList.Add(My.Resources._2_Clubs)
        imgList.Add(My.Resources._2_Diamonds)
        imgList.Add(My.Resources._2_Hearts)
        imgList.Add(My.Resources._2_Spades)
        imgList.Add(My.Resources._3_Clubs)
        imgList.Add(My.Resources._3_Diamonds)
        imgList.Add(My.Resources._3_Hearts)
        imgList.Add(My.Resources._3_Spades)
        imgList.Add(My.Resources._4_Clubs)
        imgList.Add(My.Resources._4_Diamonds)
        imgList.Add(My.Resources._4_Hearts)
        imgList.Add(My.Resources._4_Spades)
        imgList.Add(My.Resources._5_Clubs)
        imgList.Add(My.Resources._5_Diamonds)
        imgList.Add(My.Resources._5_Hearts)
        imgList.Add(My.Resources._5_Spades)
        imgList.Add(My.Resources._6_Clubs)
        imgList.Add(My.Resources._6_Diamonds)
        imgList.Add(My.Resources._6_Hearts)
        imgList.Add(My.Resources._6_Spades)
        imgList.Add(My.Resources._7_Clubs)
        imgList.Add(My.Resources._7_Diamonds)
        imgList.Add(My.Resources._7_Hearts)
        imgList.Add(My.Resources._7_Spades)
        imgList.Add(My.Resources._8_Clubs)
        imgList.Add(My.Resources._8_Diamonds)
        imgList.Add(My.Resources._8_Hearts)
        imgList.Add(My.Resources._8_Spades)
        imgList.Add(My.Resources._9_Clubs)
        imgList.Add(My.Resources._9_Diamonds)
        imgList.Add(My.Resources._9_Hearts)
        imgList.Add(My.Resources._9_Spades)
        imgList.Add(My.Resources._10_Clubs)
        imgList.Add(My.Resources._10_Diamonds)
        imgList.Add(My.Resources._10_Hearts)
        imgList.Add(My.Resources._10_Spades)
        imgList.Add(My.Resources.j_Clubs)
        imgList.Add(My.Resources.J_Diamonds)
        imgList.Add(My.Resources.J_Hearts)
        imgList.Add(My.Resources.J_Spades)
        imgList.Add(My.Resources.Q_Clubs)
        imgList.Add(My.Resources.Q_Diamonds)
        imgList.Add(My.Resources.Q_Hearts)
        imgList.Add(My.Resources.Q_Spades)
        imgList.Add(My.Resources.K_Clubs)
        imgList.Add(My.Resources.K_Diamonds)
        imgList.Add(My.Resources.K_Hearts)
        imgList.Add(My.Resources.K_Spades)
        imgList.Add(My.Resources.A_Clubs)
        imgList.Add(My.Resources.A_Diamonds)
        imgList.Add(My.Resources.A_Hearts)
        imgList.Add(My.Resources.A_Spades)
    End Sub

    Private Sub BackTrackButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim r As New Random
        PictureBox1.Image = imgList(r.Next(1, imgList.Count))
    End Sub
End Class

Re: Pull pictures from Resources

Posted: Sun Jan 27, 2013 7:40 pm
by mandai
It might help if you add an event handler to BackTrackButton1_Click

Re: Pull pictures from Resources

Posted: Sun Jan 27, 2013 9:09 pm
by muttley1968
ohh that only because i copied this code after giving up and Deled the control in a rage :P so it was their and stil didnt work

Re: Pull pictures from Resources

Posted: Sun Jan 27, 2013 11:35 pm
by mandai
The code should be changing the picture. If you try setting the picturebox image to the resource does it work?

Re: Pull pictures from Resources

Posted: Mon Jan 28, 2013 4:10 am
by noypikami
'========================================================'
' i tried to change the code, i used a timer and and change the
' PictureBox1.Image = imgList(r.Next(1, imgList.Count)) to
' PictureBox1.BackgroundImage = imgList(r.Next(0, imgList.Count))
'pictureboxperperties-change to zoom
'=========================================================
'========here's the new code================================

Private Sub BackTrackButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
timer1.start
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim r As New Random
PictureBox1.BackgroundImage = imgList(r.Next(0, imgList.Count))

'This code (down) is optional- it rotate the image in picturebox
PictureBox1.BackgroundImage.RotateFlip(RotateFlipType.Rotate270FlipXY)

End Sub

Re: Pull pictures from Resources

Posted: Mon Jan 28, 2013 4:18 am
by noypikami
just use a timer then the button is used to start the timer, as soon as the timer starts it play the images randomly, but you need to change the

PictureBox1.Image = imgList(r.Next(1, imgList.Count)) to

PictureBox1.BackgroundImage = imgList(r.Next(0, imgList.Count))


or else the first item wont be included in the random play.
and set the picturebox properties to zoom.