Csharp windowform controls clear

/// <summary>
        /// 遍曆清除指定的控件
        /// 塗聚文 2011-10-18
        /// 締友計算機信息技術有限公司
        /// </summary>
        /// <param name="con"></param>
        public void ClearControl(Control.ControlCollection con)
        {
            foreach (Control C in con)
            {
                if (C.GetType().Name == "TextBox")
                    if (((TextBox)C).Visible == true)
                        ((TextBox)C).Clear();
                if (C.GetType().Name == "MaskedTextBox")
                    if (((MaskedTextBox)C).Visible == true)
                        ((MaskedTextBox)C).Clear();
                if (C.GetType().Name == "ComboBox")
                    if (((ComboBox)C).Visible == true)
                        ((ComboBox)C).Text = "";
                if (C.GetType().Name == "PictureBox")
                    if (((PictureBox)C).Visible == true)
                        ((PictureBox)C).Image = null;
            }
        }

            //在winForm調用方法
            Control.ControlCollection coll = this.Controls;
            formOperatin.ClearControl(coll);
posted @ 2011-10-19 12:44  ®Geovin Du Dream Park™  阅读(520)  评论(0编辑  收藏  举报