遍历按钮

//遍历所有按钮
foreach (Control x in this.Controls)
{
       Control y = x as Button;
       if (y != null)
       {
             //操作
       }
}

//遍历n个按钮
for(int i=1;i<n;i++)
{
        Button btn = this.Controls["button" + i.ToString()] as Button;
        //操作
}

 

posted @ 2020-10-10 14:13  知马力lly  阅读(96)  评论(0编辑  收藏  举报
Document