动态加的button怎么写事件啊
高手指点
singleItem.Click += new EventHandler(singleItem_Click)
/* * Created by SharpDevelop. * User: hellson * Date: 2008-9-27 * Time: 13:48 * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; namespace testform { /// <summary> /// Description of MainForm. /// </summary> public partial class MainForm { [STAThread] public static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // // TODO: Add constructor code after the InitializeComponent() call. // } void MainFormLoad(object sender, System.EventArgs e) { for (int i = 0; i < 3; i++) { Button btn = new Button(); btn.Text = "Test" + i.ToString(); btn.Top = i*50; btn.Click += new EventHandler(delegate { MessageBox.Show("您点击了" + btn.Text); }); Controls.Add(btn); } } } }