//初始化
public Form1()
{
foreach (Control Ctl1 in this.Controls)
FindSubButton(Ctl1);
}
public void FindSubButton(Control Ctl)
{
if (Ctl.Controls.Count > 0)
{
foreach (Control Ctl1 in Ctl.Controls)
FindSubButton(Ctl1);
}
else
{
if (Ctl is Button)
Ctl.Click += Btn_Click;
}
}
//這邊可以開始寫方法放進裡面。
private void Btn_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
switch (btn.Name)
{
case "btn_add": ADD(); break;
default: break;
}
}
留言列表