close

//初始化

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;
            }
        }

arrow
arrow
    文章標籤
    C# WinForm Button foreach
    全站熱搜
    創作者介紹
    創作者 軒軒的爸媽 的頭像
    軒軒的爸媽

    軒軒的爸媽

    軒軒的爸媽 發表在 痞客邦 留言(0) 人氣()