private Button[,] CreateButtonArray(int width, int height)
{
Button[,] buttonArray = new Button[height, width];
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
buttonArray[i, j] = new Button();
buttonArray[i, j].Click += new EventHandler(AnyButton_Click);
buttonArray[i, j].Tag = new Point(j, i);
}
}
return buttonArray;
}
private void AnyButton_Click(object sender, EventArgs e)
{
Point p = (Point)((sender as Button).Tag);
this.textBox1.Text = string.Format("You clicked button[{0}, {1}].", p.Y, p.X);
}