/// <summary>Initializes the Grid on the form /// </summary> public void Initialize() { gridLabels = new List<PanelGridHelper>(); PanelGridHelper temp; int x, y; int numInRow = panelGrid.Width / (CELL_SIZE + PADDING); for(int i = 0; i < totalColors; i++) { temp = new PanelGridHelper(i, colors); gridLabels.Add(temp); x = i % numInRow; y = i / numInRow; temp.GridElement.Location = new Point((x * CELL_SIZE) + (PADDING * (x + 1)), (y * CELL_SIZE) + (PADDING * (y + 1))); this.panelGrid.Controls.Add(temp.GridElement); temp.GridElementClicked += GridElement_Click; } }
/// <summary>Open Color Dialog when color grid item is selected /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GridElement_Click(object sender, PanelGridHelper.GridElementClickedEventArgs e) { using(ColorDialog cd = new ColorDialog()) { if(cd.ShowDialog() == DialogResult.OK) { gridLabels[e.ElementIndex].SetColor(true, cd.Color); colors[e.ElementIndex] = cd.Color; } } }