批量设置窗体控件上的属性

       /// <summary>
        /// 清空控件上的TextBox文本中的值,ComboBox、Button设置为灰色,
        /// </summary>
        /// <param name="IsEnabled">是否显示所有控件</param>
        /// <param name="status">状态信息</param>
        /// <param name="ctr">控件集合</param>
        public void ClearControlsTextValue(ref bool IsEnabled,DeviceStatusInfo status,Control.ControlCollection ctr)
        {
            if (status.PowerState == 1 || status.NetState == 1)// || status.ErrorState == "1")
            {
                foreach (Control ctrl in ctr)
                {
                    if (ctrl is TextBox)
                    {
                        ctrl.Text = "";
                    }//End if;判断是不是文本控件。

                    if (ctrl is ComboBox)
                    {
                        ComboBox comboBoxPower = ctrl as ComboBox;

                        if (comboBoxPower.Tag == null)
                        {
                            comboBoxPower.Enabled = false;
                        }//End if;判断是不是电源下拉框控件

                    }//End if;判断是不是下拉框控件。

                    if (ctrl is ProgressBar)
                    {
                        (ctr as ProgressBar).Enabled = false;
                    }//End if;判断是不是进度条控件。

                    if (ctrl.HasChildren)
                    {
                        ClearControlsTextValue(ref IsEnabled, status,ctrl.Controls);
                    }//End if; 递归子控件

                }//End foreach;遍历所有控件。

                IsEnabled = true;
            }//End if;判断设备的电源、网络、整机、故障状态。
        }
 

原文地址:https://www.cnblogs.com/xiaotuni/p/2365725.html