Random Location within Form's Borders?
Do you need something made? then ask 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.
4 posts
Page 1 of 1
Well im making a game and i need the picturebox when it is clicked form the original location it will move to a new random location and should hardly ever give the same location or a location near it too often.
Can anyone tell me how this can be done?
Can anyone tell me how this can be done?
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that 

Something like this maybe:
Code: Select all
Private Sub PictureBox1_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox1.Click
Dim R As New Random
PictureBox1.Location = New Point(R.Next(0, Me.Width - PictureBox1.Width), R.Next(0, Me.Height - PictureBox1.Height))
End Sub
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
I'll try it out and post the results 

Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that 

Code: Select all
public void getRandom()
{
Random rand = new Random();
int width = rand.Next(0, this.Width);
int height = rand.Next(0, this.Height);
}
4 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023