Getting Rectangles stacked vertically to horizontally but keeping shape
<p>I have the input done correctly all my rectangles are stacked vertically and have different colors each time a new rectangle is drawn, but I am struggling to get the output to look like the bottom pic. Please can anybody help put me on the right path.</p>

<p><img src="http://i.stack.imgur.com/vqmTL.jpg" alt="rectangles"></p>

<pre><code>    //List to strore all randomly generated rectangles
    List&lt;Rectangle&gt; rectangleCollection = new List&lt;Rectangle&gt;();
    //Counts the amount of time a rectangle needs to be drawn
    int count = 0;

    public static Random ran = new Random();

    void CreateRectangle()
    {
        int TallestRectangle = 0; ;


        int PrevRecY = 0;

        Graphics graphic = pictureBox1.CreateGraphics();
        SolidBrush brush;

        foreach (Rectangle rect in rectangleCollection)
        {
            if (rect.Height &gt; TallestRectangle)
                TallestRectangle = rect.Height;
        }

        foreach (Rectangle rect in rectangleCollection)
        {
            graphic.FillRectangle(brush = new SolidBrush(Color.FromArgb(ran.Next(1, 255), ran.Next(1, 255), ran.Next(1, 255))),
                new Rectangle(rect.X + PrevRecY, (TallestRectangle - rect.Height), rect.Width, rect.Height));

            PrevRecY += rect.Width;
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        count = int.Parse(textBox1.Text);
        for (int i = 0; i &lt; count; i++)
        {
            GetRandomRectangle();
        }
        CreateRectangle();
    }

    void GetRandomRectangle()
    {
        Graphics graph = this.CreateGraphics();
        int x = 0;
        int y = 0;

        int width = ran.Next(20, 100);
        int height = ran.Next(30, 150);

        Rectangle rec1 = new Rectangle(x, y, width, height);
        rectangleCollection.Add(rec1);
    }
</code></pre>
