首页 > 代码库 > 将动态的角色复选框存入到Panel里面

将动态的角色复选框存入到Panel里面

1,取出角色数据源

var role = Role.SelectList();

2.设置样式
            int x = 0;
            int width = 11;
            int hang = 1;
            CheckBox ckb = null;
            foreach (var roleDto in role)
            {
                if (width > 408)
                {
                    hang += 10;
                    width = 11;
                }

3,生成新的复选框
                ckb = new CheckBox();
                ckb.Text = roleDto.RoleName;
                ckb.Tag = roleDto.SysNo;
                ckb.Location = new Point(width, 2 * hang);
                x = ckb.Text.Length;
                ckb.Size = new Size(x * 15 + 22, 16);
                width = ckb.Location.X + ckb.Size.Width + 10;

4,将复选框放入到Panel里面
                pn_checkboxList.Controls.Add(ckb);
            }