c# 代码生成6个checkbox 并初始化已知的一个数组到checkboxtext内

2025-06-21 18:56:58
推荐回答(1个)
回答1:

             /*c# 代码生成6个checkbox 并初始化已知的一个数组到checkboxtext内 */
            CheckBox[] 控件组 = Array.ConvertAll(new string[6], 控件 => new CheckBox());
            Boolean[] 数据组 = { true, false, false, true, false, true };
            int 数 = 数据组.Length;
            foreach (CheckBox 多选 in 控件组)
            {
                多选.Text = (数--).ToString("多选00");
                多选.Name = 数.ToString("多选00");
                多选.Parent = this;
                多选.Anchor = (AnchorStyles.Top | AnchorStyles.Left);
                多选.Location = new Point(100 * 数, 22);
                多选.Checked = 数据组[数];
            }