Random pictures loaded in picturebox from my.resources
Hi guys,
I have one little dillema:
I have a picture box and 10 images I want to load randomly. I cannot use imagelist because these images have a width of 400 and imagelist limits the width to 256. I have added these images to my.resources.
The thing is I cannot figure out how can I randomly load each of these pictures to this picturebox
Any help will be greatly appreciated.
Thanks
Re: Random pictures loaded in picturebox from my.resources
try this:
vb Code:
dim images() as bitmap = {my.resources.imagename1,my.resources.imagename2...my.resources.imagename10}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
picturebox1.image = images(new random().next(0,10))
End Sub
Re: Random pictures loaded in picturebox from my.resources
Thanks. I was using something similar inside a function and I had some errors. Your solution works. Thanks
Re: Random pictures loaded in picturebox from my.resources
One more thing though, If I want to add a certain link to each picture, how do I know when a certain picture is loaded into the picturebox?
Re: Random pictures loaded in picturebox from my.resources
use the picturebox tag property to store the image array index
Re: Random pictures loaded in picturebox from my.resources
how can I do this in code?
Thanks
Re: Random pictures loaded in picturebox from my.resources
what sort of link do you want to associate with each image? will it always be the same?
heres how to assign the array index to the picturebox. let me know about the link. we might be able to improve it.
vb Code:
dim images() as bitmap = {my.resources.imagename1,my.resources.imagename2...my.resources.imagename10}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dim index as integer = new random().next(0,10)
picturebox1.image = images(index)
picturebox1.tag = index
End Sub
Re: Random pictures loaded in picturebox from my.resources
different hyperlink for each image
Re: Random pictures loaded in picturebox from my.resources
vb Code:
dim images() as bitmap = {my.resources.imagename1,my.resources.imagename2...my.resources.imagename10}
dim links() as string = {"link1","link2",...,"link10"}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dim index as integer = new random().next(0,10)
picturebox1.image = images(index)
picturebox1.tag = links(index)
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
MsgBox(PictureBox1.Tag)
End Sub
Re: Random pictures loaded in picturebox from my.resources
I want to make the links available on PictureBox1_Click event. Each time I click a image displayed in the picturebox should take me to the corresponding hyperlink for that image.
Any ideas on that?
Re: Random pictures loaded in picturebox from my.resources
vb Code:
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
if PictureBox1.Tag isnot nothing then process.start(PictureBox1.Tag)
End Sub
Re: Random pictures loaded in picturebox from my.resources