创建一个Windows窗体应用程序,通过复选框的选中状态设置用户的操作权限。在默认窗体中添加5个CheckBox控件,Text属性分别设置为“基本信息管理”、“进货管理”、“销售管理”、“库存管理”和“系统管理”,主要用来表示要设置的权限;添加一个Butten按钮,用来显示选择的权限。
完整示例代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp32
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox5_CheckedChanged(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
string strPop = "您选择的权限如下:";
foreach (Control ctrl in this.Controls)//遍历窗体中的所有控件
{
if (ctrl.GetType().Name == "CheckBox")//判断是否为CheckBox
{
CheckBox cBox = (CheckBox)ctrl;//创建CheckBox对象
if (cBox.Checked == true)//判断CheckBox控件是否选中
{
strPop += "
" + cBox.Text;//获取CheckBox控件的文本
}
}
}
MessageBox.Show(strPop);
}
}
}
页面更新:2024-05-10
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号