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.
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
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
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
It might help if you add an event handler to BackTrackButton1_Click
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
The code should be changing the picture. If you try setting the picturebox image to the resource does it work?
'========================================================'
' 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
' 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.
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.
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
Copyright Information
Copyright © Codenstuff.com 2020 - 2023