Large Quantities
-
I understand the idea of how to make a bunch of rectangles in random places, but I just can't follow through. You would have
rect1 - 25
. You would haveRandom r
. How would I make them draw at random places on a form? Thanks in advance.- I love D-flat!
-
I understand the idea of how to make a bunch of rectangles in random places, but I just can't follow through. You would have
rect1 - 25
. You would haveRandom r
. How would I make them draw at random places on a form? Thanks in advance.- I love D-flat!
Hi, in the OnPaint method of the Control/Form you want to draw your shapes in, have a for loop that generates random x,y,width,height values (all within legal bounds), and call Graphics.DrawRectangle (or FillRectangle) for each of them. Alternatively, generate those numbers elsewhere and store them; then have your OnPaint feed them to Graphics.DrawRectangle. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
-
Hi, in the OnPaint method of the Control/Form you want to draw your shapes in, have a for loop that generates random x,y,width,height values (all within legal bounds), and call Graphics.DrawRectangle (or FillRectangle) for each of them. Alternatively, generate those numbers elsewhere and store them; then have your OnPaint feed them to Graphics.DrawRectangle. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
How would I select a large amount of (say) rect1 - 25? I saw a post a while back that did something close, but I can't find it. It's like... (my example)
rect(and a for loop here) { }
... or something like it -- modified at 11:28 Saturday 1st December, 2007- I love D-flat!
-
How would I select a large amount of (say) rect1 - 25? I saw a post a while back that did something close, but I can't find it. It's like... (my example)
rect(and a for loop here) { }
... or something like it -- modified at 11:28 Saturday 1st December, 2007- I love D-flat!
Something along these lines:
List< Rectangle> rects=new List< Rectangle>;
Random rand=new Random();
for (int i=0; i< RECT_COUNT; i++) {
int x=rand.Next(xBounds);
int y=rand.Next(yBounds);
int w=rand.Next(widBounds);
int h=rand.Next(heiBounds);
Rect r=new Rectangle(x,y,w,h);
rects.Add(r);
}
...
Graphics g=e.Graphics;
foreach(Rectangle r in rects) {
g.DrawRectangle(r);
}:)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
-
Something along these lines:
List< Rectangle> rects=new List< Rectangle>;
Random rand=new Random();
for (int i=0; i< RECT_COUNT; i++) {
int x=rand.Next(xBounds);
int y=rand.Next(yBounds);
int w=rand.Next(widBounds);
int h=rand.Next(heiBounds);
Rect r=new Rectangle(x,y,w,h);
rects.Add(r);
}
...
Graphics g=e.Graphics;
foreach(Rectangle r in rects) {
g.DrawRectangle(r);
}:)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets
Oh. Thanks.
- I love D-flat!