Exemplo n.º 1
0
        private void DrawGrid()
        {
            this.Invoke((Action)(() =>
            {
                drawBox.Image = DrawArea;
                graphics = Graphics.FromImage(DrawArea);
            }));

            SolidBrush brush = new SolidBrush(Color.Black);
            Pen        pen   = new Pen(Color.Black);

            float w = (drawBox.Width / grid.Width + 1);
            float h = (drawBox.Height / grid.Height + 1);

            for (int i = 0; i < grid.Width; i++)
            {
                for (int j = 0; j < grid.Height; j++)
                {
                    if (grid.IsAlive(i, j))
                    {
                        brush.Color = Color.LimeGreen;
                    }
                    else
                    {
                        brush.Color = Color.Black;
                    }
                    Rectangle rect = new Rectangle((int)(i * w), (int)(j * h), (int)w, (int)h);
                    graphics.FillRectangle(brush, rect);
                    graphics.DrawRectangle(pen, rect);
                }
            }
        }