title: Recursively draw rectangles in WinForms
body: <p>I'm currently coding a Sierpinski Carpet. Now i have the problen, that it works per iteration only once and not at every square on my whole screen.
  This is the code i use:</p>
  <pre><code>private void Carpet(Graphics g, SolidBrush brush, Single
      x, Single y, Single width, Single height, int iteration)
      {
          if (iteration == 0) {}
          
          else
          {
             
             
            
            for (int i = 0; i &lt; iteration + 1; i++)
              {
  
                   width = Convert.ToSingle(Width / Math.Pow(3,i-1));
                   height = Convert.ToSingle(Height / Math.Pow(3, i-1));
                  
  
                  Single x1 = x + width/3;
                  Single x2 = x1 + width;
                  Single x3 = x2 + width;
                  Single y1 = y + height/3;
                  Single y2 = y1 + height;
                  Single y3 = y2 + height;
  
  
                  g.FillRectangle(brush, x1, y1, width / 3, height / 3);
                  g.FillRectangle(brush, x1, y2, width / 3, height / 3);
                  g.FillRectangle(brush, x1, y3, width / 3, height / 3);
                  g.FillRectangle(brush, x2, y1, width / 3, height / 3);
                  g.FillRectangle(brush, x2, y3, width / 3, height / 3);
                  g.FillRectangle(brush, x3, y1, width / 3, height / 3);
                  g.FillRectangle(brush, x3, y2, width / 3, height / 3);
                  g.FillRectangle(brush, x3, y3, width / 3, height / 3);
                  
              }
          }
  
      }
  </code></pre>
  <p>How can i enhance my code, so it recursively draws Rectangles everywhere and not just on the first part of my Screen.
  <a href="https://i.stack.imgur.com/UwODd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UwODd.png" alt="enter image description here" /></a></p>