Pull pictures from Resources

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
6 posts Page 1 of 1
Contributors
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Pull pictures from Resources
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
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Pull pictures from Resources
mandai
It might help if you add an event handler to BackTrackButton1_Click
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

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
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Pull pictures from Resources
mandai
The code should be changing the picture. If you try setting the picturebox image to the resource does it work?
User avatar
noypikami
VIP - Donator
VIP - Donator
Posts: 151
Joined: Sat Dec 22, 2012 1:49 am

Re: Pull pictures from Resources
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
Last edited by noypikami on Mon Jan 28, 2013 4:20 am, edited 1 time in total.
User avatar
noypikami
VIP - Donator
VIP - Donator
Posts: 151
Joined: Sat Dec 22, 2012 1:49 am

Re: Pull pictures from Resources
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.
6 posts Page 1 of 1
Return to “Coding Help & Support”