Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 86,373 VB.NET Programmers. There are 1,421 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a VB.NET Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

Randomize Picture Box from ImageList

 
Reply to this topicStart new topic

Randomize Picture Box from ImageList

ryand
post 8 May, 2008 - 11:42 AM
Post #1


New D.I.C Head

*
Joined: 8 May, 2008
Posts: 6



Hey this may be a very simplistic thing to do, but I want to be able to randomize what image the picture box displays, and I want to pick it from an Image list with the collection that I want to use.

I'm trying to use a custom function so that it can be repeated.

Thanks,
Ryan
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


ferrari12508
post 8 May, 2008 - 12:12 PM
Post #2


Feelin' L33t? if so, die!

Group Icon
Joined: 2 Nov, 2007
Posts: 914

Welcome to the dream.in.code's programming help forums! In order to better help you and other members, there are a couple rules we'd like you to follow:
Post the code you have so far using the [code] tags. We can't help you if you don't post your code. We will not do your homework for you. You MUST show some effort.
We have a 0-tolerance cheating policy. If we find you are trying to cheat, you will be warned, and subsequently banned. You MUST show some effort.
Make your questions and answers clear and concise. Explain the problem, any errors you are receiving, and the code causing the errors.
Utilize the "Search" feature. Many questions have already been asked and answered in another thread.
If you are answering someone’s question, only do so if they have made an attempt. We will delete any posts providing code when a user has not shown some effort. Kindly ask the user to post what they've done so far.
If you absolutely must hire someone to do your code, do NOT post in the forums. All correspondence must be over PM or E-Mail.
Following these simple guidelines helps us help you faster and provides others in the future a way to learn. Thank you for your cooperation.

In other words, You do some work, we will help you from there
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

ryand
post 8 May, 2008 - 02:14 PM
Post #3


New D.I.C Head

*
Joined: 8 May, 2008
Posts: 6

here is what code I have, I tried using an array, but I'm not sure if thats the best way:

Private RandomImage() as Image {ImageList1.Images.Item(1), ImageList1.Images.Item(2), etc...}

...

Private Sub btnRandomize_Click...

Dim rnd as new random
Pic1 = rnd.RandomImage (This is my problem spot)

End Sub

This post has been edited by ryand: 8 May, 2008 - 02:14 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Martyr2
post 8 May, 2008 - 03:01 PM
Post #4


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 3,561

Check out the function below. This function will set our picturebox (titled PictureBox1) to a random image contained in our imagelist control (titled ImageList1) whenever the user clicks the button (titled Button1).

vb

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Create a integer and new Random object
Dim intPic As Integer
Dim rand As New Random

' Pick a random number between 0 and the number of images in our imagelist control
intPic = rand.Next(0, ImageList1.Images.Count)

' Now set the picturebox image equal to the image chosen from the imagelist box randomly using the random
' integer
PictureBox1.Image = ImageList1.Images(intPic)
End Sub


What we do is pick a random number from 0 to the number of images in the imagelist. We then use this random number to then access the image at that index from the imagelist and set that to the picturebox.

Enjoy!

"At DIC we be random picture picking code ninjas... we are less picky on which we pick, taco del mar, taco time, or taco bell. Ok just kidding, we are picky on that too." decap.gif
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

ryand
post 8 May, 2008 - 06:48 PM
Post #5


New D.I.C Head

*
Joined: 8 May, 2008
Posts: 6

thank you very much, I'll try it out.

(5 minutes later)
Thank you very much, it works perfectly, appreciate the assistance.

This post has been edited by ryand: 8 May, 2008 - 06:52 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 02:43AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month