///
/// 创建一个动态按钮,并返回这个实例
///
/// 按钮的事件过程
System.Windows.Forms.Button CreateButton(EventHandler buttonClick)
{
System.Windows.Forms.Button _button=new System.Windows.Forms.Button();
_button.Text="动态按钮";
_button.Click+=buttonClick;
_button.Visible=_button.Enabled=true;
return _button;
}
void Test(System.Windows.Forms.Form f)
{
System.Windows.Forms.Button _button=CreateButton(new EventHandler(Button_Click));
f.Controls.Add(_button);
_button.Location=new System.Drawing.Point(12, 12);
}
void Button_Click(object sender, EventArgs e)
{
System.Windows.Forms.MessageBox.Show("动态按钮单击事件!");
}