Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Large Quantities

Large Quantities

Scheduled Pinned Locked Moved C#
tutorialquestionlounge
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MasterSharp
    wrote on last edited by
    #1

    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 have Random r. How would I make them draw at random places on a form? Thanks in advance.

    - I love D-flat!

    L 1 Reply Last reply
    0
    • M MasterSharp

      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 have Random r. How would I make them draw at random places on a form? Thanks in advance.

      - I love D-flat!

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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


      M 1 Reply Last reply
      0
      • L Luc Pattyn

        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


        M Offline
        M Offline
        MasterSharp
        wrote on last edited by
        #3

        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!

        L 1 Reply Last reply
        0
        • M MasterSharp

          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!

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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


          M 1 Reply Last reply
          0
          • L Luc Pattyn

            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


            M Offline
            M Offline
            MasterSharp
            wrote on last edited by
            #5

            Oh. Thanks.

            - I love D-flat!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups