郑德才博客 记录学习,记录工作,学习知识分享!

C# 如何在代码中对所有button控件操作啊

List<Control> buttonList = new List<Control>();
foreach (Control control in Controls)  //遍历所以的控件
     {
                    if (control is Button)    //判断是否是按钮控件
                    {
                          buttonList.add(control );
           }
   }

这样你就可以只操作buttonList了。
设置属性的时候,同样要遍历buttonList
for(int i = 0;i < buttonList.Count;i++)
{
     Button b = buttonList[i] as Button;
     b.Text = "xxxxx";  //等等属性之类的东西
}

2012年7月7日 | 发布:郑德才博客 | 分类:学习之路 | 评论:2

留言列表:

  • 影楼营销 发布于 2012/7/9 10:10:36  回复
  • 支持一下了哈
  • 郑州摄影工作室 发布于 2012/7/14 11:07:01  回复
  • 原来是这样的啊

发表留言: