randomizing pictureboxes' location within four specific points

ljpv14

Active member
Joined
Nov 28, 2011
Messages
44
Programming Experience
3-5
hey guys! i really need your help in randomizing picturebox location given four points

example:

i have 4 picture boxes. these boxes should be place at points (145, 190) (210, 190) (290, 190) (37, 190). this will display the pictureboxes at a horizontal line. i'm adding a functionality that when i press spacebar or click a button, these coordinates will be randomized and be assigned to my four pictureboxes just like in text twist but no animations. HELP PLEASE!
 
First up, I'm going to assume that you are not really using .NET 1.0. It's possible but highly unlikely. Please confirm that that is the version you're using or else edit your profile.

Put the Points in an array and put the PictureBoxes in another array. Assuming .NET 3.5 or later, you can then randomise one of the arrays like so:
Dim rng As New Random

myArray = myArray.OrderBy(Function(n) rng.NextDouble()).ToArray()
You can then use a For loop to loop through the arrays and, at each index, assign the Point from one array to the Location of the PictureBox in the other.
 
Oyeah, I didn't notice that my profile displays that I'm using .net 1.0. I'm new here at vbdotnetforums. By the way, thank you for the solution. I finally got the approach when traversing arrays and assigning their values. Great! Thanks! :D
 
Just a follow up question regarding randomization. Is it possible that if I randomize a picture box, a certain array of characters will also be randomized with the same value with the randomized picture boxes. I have a picture box with 4 images. This images displays letters 'a' 'b' 'c' and 'd'. I also have a array of characters with values 'a' 'b' 'c' and 'd'. I want to randomize the array of characters with the same order as the randomized picture boxes.

picturebox a = character 'a'
picturebox b = character 'b'
picturebox c = character 'c'
picturebox d = character 'd'

Thank you!
 
You don't need to randomise the characters. You just need to create a 1:1 correspondence between the the PictureBoxes and the characters. You could do that by either assigning the characters to the Tag properties of the PictureBoxes or with a Dictionary(Of PictureBox, Char). That way, you just randomise the PictureBox array and then, for any particular PictureBox, you use it to get the corresponding character from the appropriate location.
 
or could i just assign a value to its tag property by typing. picturebox.tag = "a"? is this possible?

When you tried it for yourself, did it work?
 
Back
Top