int i, j;
this.buttonArr = new Button[4, 4];
for (i = 0; i <= 3; i++)
{
for (j = 0; j <= 3; j++)
{
this.buttonArr[i, j] = new System.Windows.Forms.Button();
this.buttonArr[i, j].Location = new System.Drawing.Point(70 + i * 80, 70 + j * 40);
this.buttonArr[i, j].Name = "buttonarr" + (i + j * 4).ToString();
this.buttonArr[i, j].Size = new System.Drawing.Size(80, 40);
this.buttonArr[i, j].TabIndex = i * 10 + j;
this.buttonArr[i, j].Text = "button" + (i + j * 4).ToString();
this.buttonArr[i, j].UseVisualStyleBackColor = true;
this.buttonArr[i, j].Click += new System.EventHandler(this.button1_Click);
this.Controls.Add( this.buttonArr[i, j]);
}
}
*********************************************************************
private void button1_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
MessageBox.Show(b.Name.ToString());
}
沒有留言:
張貼留言