private void btnClick(object sender, EventArgs e) { ButtonCoord btn = (ButtonCoord)sender; if (btn.BackColor == COLOR_BNT_NOT_PRESSED) { btn.BackColor = COLOR_BNT_PRESSED; if (EsElPrimero) { if (Coord1 != null) { Coord1.BackColor = COLOR_BNT_NOT_PRESSED; } Coord1 = btn; } else { if (Coord2 != null) { Coord2.BackColor = COLOR_BNT_NOT_PRESSED; } Coord2 = btn; } EsElPrimero = !EsElPrimero; } else { btn.BackColor = COLOR_BNT_NOT_PRESSED; if (EsElPrimero) { Coord2 = null; } else { Coord1 = null; } EsElPrimero = !EsElPrimero; } lblCoords.Text = $"1-{Coord1?.Text} 2-{Coord2?.Text}"; if (Coord1 != null && Coord2 != null) { txtCoordKey.Text = $"{Coord1.Key}{Coord2.Key}"; Clipboard.SetText(txtCoordKey.Text); } else { txtCoordKey.Text = ""; } }
private void CreateButtons() { for (int col = 0; col < 7; col++) { for (int row = 0; row < 5; row++) { var btn = new ButtonCoord(); btn.Col = col; btn.Row = row; btn.Dock = DockStyle.Fill; btn.Click += btnClick; tableLayoutPanel1.Controls.Add(btn, col, row); } } }