刚才你问的就是我给你答的,这回接着给你答,见代码:
Button[,] matrix = new Button[11, 11];
for (int i = 1; i < 11; i++)
for (int j = 1; j < 11; j++)
{
Button btn = new Button();
btn.Top = 40 + i * 25;
btn.Left = 200 + j * 25;
btn.Visible = true;
btn.Height = 25;
btn.Width = 25;
btn.Name = "btn" + i + j;
btn.Click += new System.EventHandler(this.buttonArr_Click);
this.Controls.Add(btn);
matrix[i, j] = btn;
}
private void buttonArr_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
MessageBox.Show("你点了" + btn.Name);
}
根据id获取,如果是你利用别的gridview等控件创建的可以使用相应的DataBind事件去获取。
所有的按钮使用同一个事件处理程序
比如
private void button_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
//这里btn就是点中的按钮
}