您的位置:首页 > 编程语言 > C#

【C#笔记】控件数组与事件

2015-07-17 15:12 459 查看
private void Form1_Load(object sender, EventArgs e)
{

Button[] but = new Button[10];

for (int i = 0; i < 10; i++)
{
but[i] = new Button();
but[i].Text = "按钮" + i;
but[i].Left = 82 * i;
but[i].Width = 80;
this.Controls.Add(but[i]);
but[i].Click += new System.EventHandler(this.but_Click);//绑定事件
}

private void but_Click(object sender,System.EventArgs e)
{
MessageBox.Show(((Button)sender).Text+"01");//用sender 判定是那个控件
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: