I am trying to make a simple five in a row (gomoku) game for two players using windows forms and c#. I put a picturebox with a picture and stretched it out on the form. Now I want to put labels at all the intersections on the picture board so a user can click them and change their background color to black or white.
How can I make the labels created clickable on the form?
public partial class Form1 : Form { int labelCount = 0; int iteration = 0; public Form1() { InitializeComponent(); Label[] board = new Label[361]; for (int i = 0; i < 361; i++) { board[i] = new Label { Name = "label" + i, Height = 55, Width = 55, MinimumSize = new Size(55, 55), Text = "label " + i }; } int x = 0; int y = 0; foreach (var Label in board) { if (x >= 580) { x = 0; y = y + Label.Height + 55; } Label.Location = new Point(x, y); this.Controls.Add(Label); x += Label.Width; } } }
Should I make a one-dimensional [361] or two-dimensional array
[{A,1}, {A,2}....{D,1}]
to easily check for a winner? How can I connect it to the created labels so the array data corresponds to the objects on the board?