要求:如下图
窗体界面:
源代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 利用选择控件实现权限设置
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region 初始化窗体代码
private void Form1_Load(object sender, EventArgs e)
{
ckLInfo.Visible = false;
ckLShop.Visible = false;
ckLMange.Visible = false;
ckLSell.Visible = false;
ckLShop.Items.Add("采购进货");
ckLShop.Items.Add("采购退货");
}
#endregion
#region 自定义CheckedListBox控件中Items全选的CheckAll()方法
private void CheckAll(object checkList)
{
if (checkList.GetType().ToString() == "System.Windows.Forms.CheckedListBox")
{
CheckedListBox ck1 = (CheckedListBox)checkList;
//把传入的参数的属性通过循环变成已选中
for (int i = 0; i < ck1.Items.Count; i++)
{
//SetItemCheckState设置指定索引处项的复选状态,语法为:SetItemCheckState(索引,控件状态(选中CheckState.Checked或不选中CheckState.Unchecked))
ck1.SetItemCheckState(i, CheckState.Checked);
}
}
}
#endregion
#region 自定义CheckedListBox控件中Items取消全选的EscCheckAll()方法
private void EscCheckAll(obj