This is my class, where I have various properties and also the Panel control:
public class Square
{
private Panel _pSquare;
public Panel PSquare
{
get { return _pSquare; }
set { _pSquare = value; }
}
....
This is the Form Load EventHandler, where a bunch of Square Objects are created:
private void Form1_Load(object sender, EventArgs e)
{
for (var n = 0; n < gridSize; n++)
{
for (var m = 0; m < gridSize; m++)
{
Square squareboard = new Square(n, m);
squareboard.PSquare.Click += squareEvent;
...
When the user clicks on a Panel, the pSquare_Click EventHandler is called, so that part works.
private void pSquare_Click(object sender, EventArgs e)
{
The problem I have is: how to access the properties of class Square in this EventHandler?
Your Square class could look like this:
In your form you could make the panels first, and then generate a collection of squares by looping through the panels: