private void RenderGraphics(List <Point> cells) { using (Graphics gridGraphics = PanGrid.CreateGraphics()) { using (BufferedGraphicsContext bgc = new BufferedGraphicsContext()) { using (BufferedGraphics bg = bgc.Allocate(gridGraphics, PanGrid.ClientRectangle)) { RenderCells(cells, bg); RenderGrid(bg); bg.Render(gridGraphics); } } } OnRender?.Invoke(_cells.Count); }
private void DrawCell(MouseEventArgs e) { if (e.Button != MouseButtons.Left && e.Button != MouseButtons.Right) { return; } using (Graphics graphics = PanGrid.CreateGraphics()) { int x = GetGridCoord(e.X, GridSize.Width); int y = GetGridCoord(e.Y, GridSize.Height); Brush cellBrush = e.Button == MouseButtons.Left ? Brushes.GreenYellow : Brushes.Black; Rectangle cellRect = new Rectangle(x, y, CellSize, CellSize); graphics.FillRectangle(cellBrush, cellRect); graphics.DrawRectangle(_gridPen, cellRect); UpdateLivingCellsList(e, x, y); OnRender?.Invoke(_cells.Count); } }