I am making a reaction game that involves the user clicking a picturebox which randomizes its location.
The tricky part is to randomize the picturebox's location so that it appears within the bounds of a panel which i have created. The reason for this is that i have other controls on the form. Not sure if a panel would be the best way of going about this but i am not sure where to start.
The picturebox's size is (70,55) and the panel's size is (640,400) in location (40,69) if it makes any difference.
I have the following code so far:
Dim rnd1 As Integer = panel1.Width * Rnd()
Dim rnd2 As Integer = panel1.Height * Rnd()
pb1.Top = rnd2
pb1.left = rnd1
while it works it randomizes the picturebox right on the edges of the panel so that some randomizations result in the picturebox not being visible at all. What code would i have to use so that the picturebox is completely visible and does not cross the bounds of the panel?
Thanks
Aucun commentaire:
Enregistrer un commentaire