标签:style blog ar color os sp for on div
public Form1() { InitializeComponent(); button1.Click += new EventHandler(button_Click); button2.Click += new EventHandler(button_Click); button3.Click += new EventHandler(button_Click); } private void button_Click(object sender, EventArgs e) { Button tempButton = sender as Button; if (tempButton != null) MessageBox.Show(tempButton.Text); }
/*生成Button的代码*/ for(var i=0; i<10; i++){ Button dynamicBtn = new Button(); dynamicBtn.Text = string.Format("这是第{0}个按钮", i); dynamicBtn.Tag = i; dynamicBtn.Click += new EventHandler(DynamicButtonClick); Panel1.Controls.Add(dynamicBtn) }
/*事件处理函数*/ private void DynamicButtonClick(object sender, EventArgs e){ Button currentBtn = sender as Button; MessageBox.Show(currentBtn.Tag.ToString(), "按钮编号"); }
标签:style blog ar color os sp for on div
原文地址:http://www.cnblogs.com/ilookbo/p/4117983.html