The following code is responsible for creating a 5 by 5 grid of buttons. Thanks to people help, i could insert lambda expretion that will pass an information 'which button from the grid is pressed' to other functions. The thing is, that i need it to distinguish wheter left or right mouse button is pressed and i have no clue how to do that. Any hints or links to other posts/articles would be very helpfull.
Button[] grid5x5 = new Button[25];
void Spawn5x5Grid()
{
// Position of the first button
int x = 50, y = 150;
int count = 0;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
grid5x5[count] = new Button
{
Size = new Size(31,31),
Location = new Point(x, y)
};
this.Controls.Add(grid5x5[count]);
grid5x5[count].Click += (o, ee) =>
{
Button button = o as Button;
// index variable contains the position of the button in
// array
int index = Array.IndexOf(grid5x5, button);
};
count++;
x = x + 31;
}
x = 50;
y = y + 31;
}
}