I'm creating 50 picture boxes where all of them has a constant width and height of 50 and on run time, i randomly place them in random locations on the form but the problem is some picture boxes overlaps with each other... any idea on how to randomly place the picture boxes on the form with no overlapping?
it2051229
-3
Junior Poster in Training
Recommended Answers
Jump to PostMake an array of non overlapping locations.
Randomly select from this array.
Jump to PostWhy not use location 51,0 for picbox 2? That way it will be placed just right of picbox 1 and not overlap.
Jump to PostUsually you do a forumla such as
int pic_width=50; int pic_height=50; for(w=0;w<10;w++) { picturebox[i].top=0; picturebox[i].left=(pic_width+1)*i; picturebox[i].height=pic_height; picturebox[i].width=pic_height; }
this means box1 ends up at 0,0 , box2 51,0, box3 102,0 etc so they dont overlap.
All 10 Replies
ddanbe
2,724
Professional Procrastinator
Featured Poster
it2051229
-3
Junior Poster in Training
ddanbe
2,724
Professional Procrastinator
Featured Poster
LizR
171
Posting Virtuoso
it2051229
-3
Junior Poster in Training
ddanbe
2,724
Professional Procrastinator
Featured Poster
it2051229
-3
Junior Poster in Training
LizR
171
Posting Virtuoso
it2051229
-3
Junior Poster in Training
LizR
171
Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.