C#中容器控件GroupBox、Panel、TabControl
来源:互联网 发布:linux命令文件拷贝到 编辑:程序博客网 时间:2024/05/17 03:26
实现如图所示登录界面,当输入正确用户名及密码时,转到主界面,否则给出错误提示。要求不同身份的登陆者拥有不同的操作权限。
源代码:
1.初始化三个string类型的变量分别用来存储用户名、密码和身份。
- string yhm, mm, sf;
- private void Form1_Load(object sender, EventArgs e)
- {
- yhm=mm="";
- sf=radioButton1.Text;
- }
2.为三个单选按钮添加CheckedChanged事件处理程序
1>学生:
- private void radioButton1_CheckedChanged(object sender, EventArgs e)
- {
- if(radioButton1.Checked)
- {
- sf=radioButton1.Text;
- checkBox1.Checked = true;
- checkBox2.Checked=checkBox3.Checked=checkBox4.Checked=checkBox5.Checked=false;
- }
- }
2>教师:
- private void radioButton2_CheckedChanged(object sender, EventArgs e)
- {
- if (radioButton2.Checked)
- {
- sf = radioButton2.Text;
- checkBox1.Checked=checkBox2.Checked = true;
- checkBox3.Checked = checkBox4.Checked = checkBox5.Checked = false;
- }
- }
3>管理员:
- private void radioButton3_CheckedChanged(object sender, EventArgs e)
- {
- if (radioButton3.Checked)
- {
- sf = radioButton3.Text;
- checkBox1.Checked = checkBox2.Checked = checkBox3.Checked = checkBox4.Checked = checkBox5.Checked = true;
- }
- }
3.为四个Button按钮添加Click事件:
1>确定:
- private void button1_Click(object sender, EventArgs e)
- {
- yhm = textBox1.Text.Trim();
- mm = textBox2.Text.Trim();
- if (yhm == "xs" && mm == "xs" && sf == "学生")
- {
- tabControl1.SelectedTab = tabPage2;
- panel2.Visible = true;
- button4.Enabled = button5.Enabled = button6.Enabled = button7.Enabled = false;
- panel1.Visible = false;
- }
- else if (yhm == "js" && mm == "js" && sf == "教师")
- {
- tabControl1.SelectedTab = tabPage2;
- panel2.Visible = true;
- button3.Enabled=button4.Enabled = true;
- button5.Enabled = button6.Enabled = button7.Enabled = false;
- panel1.Visible = false;
- }
- else if (yhm == "gly" && mm == "gly" && sf == "管理员")
- {
- tabControl1.SelectedTab = tabPage2;
- panel2.Visible = true;
- button3.Enabled=button4.Enabled = button5.Enabled = button6.Enabled = button7.Enabled = true;
- panel1.Visible = false;
- }
- else
- MessageBox.Show("用户名或密码错误","登录失败");
- }
2>取消:
- private void button2_Click(object sender, EventArgs e)
- {
- this.Close();
- }
3>注销登录:
- private void button8_Click(object sender, EventArgs e)
- {
- panel1.Visible = true;
- panel2.Visible = false;
- textBox1.Text = textBox2.Text = "";
- radioButton1.Checked = true;
- tabControl1.SelectedTab = tabPage1;
- }
4>退出系统:
- private void button9_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
运行结果展示图:
0 0
- C#中容器控件GroupBox、Panel、TabControl
- C#中容器控件GroupBox、Panel、TabControl的应用
- C#控件 GroupBox和Panel的区别
- 容器里panel控件和groupBox控件的区别
- 分组类控件(Panel)分组框控件(groupBox)和选项卡控件(TabControl)
- C#如何在Panel或者GroupBox控件中自由地切换其他窗体
- C#中GroupBox控件的使用
- C#用了皮肤后,Panel和GroupBox 容器背景透明
- C#中TabControl控件应用实例
- c#如何将子窗体显示到父窗体的容器(panel)控件中
- C#打印GroupBox控件区域
- C# WF 删除panel容器动态添加的控件
- C# 清空panel中所有控件
- C#打印panel控件中内容
- c#中panel控件有什么作用
- 自行实现透明的控件如Panel GroupBox
- ASP:Panel控件(容器控件)
- C#中控件的使用(一)------TabControl
- Android逆向之旅—静态方式破解微信获取聊天记录和通讯录信息
- 大话之一个菜鸟小白的git历练之路
- 文件路径中“/“和”\”的区别
- thinkphp如何来判断访客为手机端或是P
- 从0开始学习 GitHub 系列之「03.Git 速成」
- C#中容器控件GroupBox、Panel、TabControl
- vector::end( )与vector::back( )
- 最小生成树(Minimum-cost Spanning Trees)(Prim算法&&Kruskal算法)
- Hawq学习笔记 --- postgresql 数据库导入导出
- 从0开始学习 GitHub 系列之「04.向GitHub 提交代码」
- 微助手 2016.11.16号正式上市
- python 第三方模块
- 从0开始学习 GitHub 系列之「05.Git 进阶」
- 排序算法(八)归并排序