动态控件--如何让他们工作呢?
比如我创建了5个button,都是用程序创建的.
我想写他们的click事件,怎么办呢?
------解决方案--------------------private void FormCalc_Load(object sender, EventArgs e)
{
Button vButton;
vButton = new Button();
vButton.Text = "保存 ";
vButton.Tag = "save ";
vButton.Parent = this;
vButton.Click += new EventHandler(vButton_Click);
vButton = new Button();
vButton.Top = 30;
vButton.Text = "载入 ";
vButton.Tag = "load ";
vButton.Parent = this;
vButton.Click += new EventHandler(vButton_Click);
}
void vButton_Click(object sender, EventArgs e)
{
switch((string)((Button)sender).Tag)
{
case "save ":
MessageBox.Show( "保存 ");
break;
case "load ":
MessageBox.Show( "载入 ");
break;
}
}