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 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.
Jump to PostThats a very tough way of doing it - while I showed you a "fixed" way of laying them out - its very simple to randomize a position using that formula.
Jump to PostWell, it does, because the forumla doesnt require you to use it in order, because its a formula. You can randomize it and slot items into place without 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.