动态创建控件,并附加上Click控件
Button button = new Button();
button.Name = "btn" + “1”;
button.Text = "开始";
button.Size = new Size(75, 23);
this.Controls.Add(button);
button.Click += new EventHandler(btn_Click);
添加Click事件
private void btn_Click(object sender, System.EventArgs e)
{
事件代码
}
动态操作控件
System.Windows.Forms.Control constrol = panel_full.Controls["btn" + (n).ToString()];
if (constrol != null)
{
Button button = (Button)constrol;
button.Location = new Point(3, 107);
}