C#:复选框操作类

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows.Forms;



namespace Common

{

    /// <summary>

    /// 复选框操作类

    /// </summary>

    public class CtlCheckBoxOperate

    {

        private CheckBox m_checkBox = null;



        /// <summary>

        /// 关联CheckBox控件

        /// </summary>

        public CheckBox refCheckBoxControl

        {

            set

            {

                m_checkBox = value;

            }

            get

            {

                return m_checkBox;

            }

        }



        /// <summary>

        /// 构造函数

        /// </summary>

        public CtlCheckBoxOperate()

        {



        }



        private static volatile CtlCheckBoxOperate m_chkbOpera = null;

        /// <summary>

        ///获取操作TextBox控件的单一实例

        /// </summary>

        public static CtlCheckBoxOperate GetInstance()

        {

            if(null == m_chkbOpera)

            {

                m_chkbOpera = new CtlCheckBoxOperate();

            }

            return m_chkbOpera;

        }



        /// <summary>

        /// 获取组件内所有选中的CheckBox文本

        /// </summary>

        /// <param name="groupBox">组控件</param>

        /// <returns>所有选中的CheckBox数量</returns>

        public int GetSelectedTexts(GroupBox groupBox, ref string[] chkbTexts)

        {

            int i = 0;

            foreach(Control control in groupBox.Controls)

            {

                if(control is CheckBox)

                {

                    chkbTexts[i] = ((CheckBox)control).Text;

                    i++;

                }

            }

            return i;

        }

    }

}

 

你可能感兴趣的:(复选框)