public void RemoveBackgroundCell() { for (int i = 0; i < CellSize.X; i++) { for (int j = 0; j < CellSize.Y; j++) { Cage background = MainForm.Controls.OfType <Cage>().Where(b => b.IsBackground && b.Position == new Point(i, j)).FirstOrDefault(); if (background != null) { MainForm.Controls.Remove(background); } } } IsBackground = false; BackgroundCages.Clear(); }
public void SetBackgroundCell(Color color = default(Color)) { if (BackgroundCages.Count == 0) { for (int i = 0; i < CellSize.X; i++) { for (int j = 0; j < CellSize.Y; j++) { Cage background = new Cage(); background.IsBackground = true; background.Position = new Point(i, j); background.BackColor = Equals(color, default(Color)) ? Color.Gainsboro : color; background.Size = CageSize; //background.Location = new Point(Location.Y + j * CageSize.Width + (CageDistance * j), Location.X + i * CageSize.Height + (CageDistance * i)); //background.PreviewKeyDown += Cage_PreviewKeyDown; BackgroundCages.Add(background); MainForm.Controls.Add(background); } } } IsBackground = true; }