日期:2014-05-18  浏览次数:20897 次

c# 如何在代码中对所有button控件操作啊,我想数组,但怎么搞
RT  


------解决方案--------------------
C# code

List<Button> btns = new List<Button>();
btns.Add(button1);

------解决方案--------------------
C# code

List<Button> btns = new List<Button>();
foreach (Control control in Controls)
  {
   if (control is Button)  
   {
      btns.Add(control);
    }
  }

------解决方案--------------------
C# code

            List<Button> btns = new List<Button>();

            foreach (Control control in Controls)
            {
                if (control is Button)
                {
                    btns.Add(control as Button);
                }
            }