C# 通过遍历设置控件属性

时间:2022-07-23
本文章向大家介绍C# 通过遍历设置控件属性,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
 foreach (Control control in this.Controls)
            {
                if (control is Button)
                {
                    if(control.Name == "button1")
                    control.Enabled = false;
                }
            }

方法二:

Label[] lb = new Label[3] { label1, label2, label3 };
            for (int i = 0; i < 3; i++)
            {
                lb[i].Text = "label*" + i.ToString();
            }