title: Efficiently draw a grid in Windows Forms
body: <p>I'm writing an implementation of Conway's Game of Life in C#. This is the code I'm using to draw the grid, it's in my panel_Paint event. g is the graphics context.</p>
  
  <pre><code>for (int y = 0; y &lt; numOfCells * cellSize; y += cellSize)
  {
       for (int x = 0; x &lt; numOfCells * cellSize; x += cellSize)
       {
            g.DrawLine(p, x, 0, x, y + numOfCells * cellSize);
            g.DrawLine(p, 0, x, y + size * drawnGrid, x);
       }
  }
  </code></pre>
  
  <p>When I run my program, it is unresponsive until it finishes drawing the grid, which takes a few seconds at numOfCells = 100 &amp; cellSize = 10. Removing all the multiplication makes it faster, but not by very much.</p>
  
  <p>Is there a better/more efficient way to draw my grid?</p>
  
  <p>Thanks</p>