C#中容器控件GroupBox、Panel、TabControl
实现如图所示登录界面,当输入正确用户名及密码时,转到主界面,否则给出错误提示。要求不同身份的登陆者拥有不同的操作权限。
源代码:
1.初始化三个string类型的变量分别用来存储用户名、密码和身份。
[csharp] view plain copy
print?
string yhm, mm, sf;
string yhm, mm, sf;
- private void Form1_Load(object sender, EventArgs e)
- {
- yhm=mm="";
- sf=radioButton1.Text;
- }
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;
- }
- }
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;
- }
- }
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;
- }
- }
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("用户名或密码错误","登录失败");
- }
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;}elseMessageBox.Show("用户名或密码错误","登录失败");}
2>取消:
- private void button2_Click(object sender, EventArgs e)
- {
- this.Close();
- }
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;
- }
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();
- }
private void button9_Click(object sender, EventArgs e){Application.Exit();}
运行结果展示图:
C#中容器控件GroupBox、Panel、TabControl相关推荐
- C#中主窗体Panel中加载其他多个窗体Panel控件
今天在技术群里,笔者遇到一个这样的问题,"有客户想让两个Form窗体的内容放到一个Form窗体中,但是两个窗体的内容超出主窗体的大小",为了解决这个问题,笔者的想法是"采 ...
- Xcode 中使用 Color Panel 查看颜色
在 Swift 开发中,我们经常会用到 Color 或 UIColor 中预置的颜色,比如 Color.red,NSColor.windowBackgroundColor. 但是有时候,Apple 预 ...
- Bootstrap中的面板(panel)
背景 写自动折叠的面板时遇到点问题,虽与面板本身无关,可看到他有序的组织,我想bootstrap肯定有完整的面板结构.果不其然. 基本结构 <div class="panel-grou ...
- Window控制面板中NVIDIA Control Panel缺失找不到文件解决方案
问题:NVIDIA Control Panel在这里打不开,提示错误信息 解决方案: 第一步:Win + R :输入regedit 第二步:Ctrl + F 搜索 NVIDIA Control Pan ...
- panel中html怎么写,panel控件有什么用 请写出Panel控件的用途
当多个panel控件重叠时,把一个panel的visible/设置为true,其它的设置为f例如有3个panel,分别为panel1,panel2,panel3 如果重叠的话,把他们的大小设置为相同大 ...
- C# 中panel的mousewheel鼠标滚轮事件触发
如果将窗体或容器控件(如Panel控件)的AutoScroll属性设置为True时,那么当窗体或Panel容不下其中的子控件时就会出现 滚动条,通过移动滚动条可以上下显示出窗体或Panel中的全部内容 ...
- Winform 中panel的mousewheel鼠标滚轮事件触发
如果将窗体或容器控件(如Panel控件)的AutoScroll属性设置为True时,那么当窗体或Panel容不下其中的子控件时就会出现 滚动条,通过移动滚动条可以上下显示出窗体或Panel中的全部内容 ...
- C# WinForm解决Panel控件中的图片刷新时会闪烁的问题
最近在项目开发过程中,使用Panel控件显示座位背景图,在分屏切换时,发现背景图会闪烁.在同事的帮助下,通过以下方法解决了: 新建一个类,继承Panel控件类,然后开启该控件的双重辅助缓冲区,禁止擦除 ...
- Winform框架中内容的学习
一.Winform框架中的内容 WinForm(一) WinForm入门与基本控件使用_阿阿阿安的博客-CSDN博客_winform winform 控件及其各个属性_weixin_30907935的 ...
最新文章
- Play 1.x框架学习之五:错误信息显示 (error message display In play framework)
- mysql 存储过程月单拆天单_为部门整理的mysql_db使用军规
- 高通camera驱动分析
- HDOJ1860 ( 统计字符 ) 【水题】
- 计算机组成原理期末复习题
- java 泛型和类型擦除_关于Java泛型和擦除
- ftl转pdf及问题集锦
- 网易数帆、云音乐、Intel、有赞最新大数据实践(PPT下载+视频回放)
- python︱六款中文分词模块尝试:jieba、THULAC、SnowNLP、pynlpir、CoreNLP、pyLTP
- JavaWeb Cookie客户端技术和Session服务端技术详解
- 快排,归并(日常复习)
- 假货泛滥是淘宝的毒瘤
- 实战四:Kaggle自行车租赁预测比赛
- 手写深度学习之优化器(SGD、Momentum、Nesterov、AdaGrad、RMSProp、Adam)
- 省市区areacode反查的精简写法
- 邹恒甫:谈点2002年后海鬼/龟和特聘教授的工资待遇和福利
- 直接数字下变频(3):希尔伯特变换法
- 日本现场常用日语词汇
- 大数据第一章(Linux环境部署JDKMysql)
- php数值变成函数,PHP实现金额数字转换成大写函数
热门文章
- mysql scott用户_在mysql中创建 oracle scott 用户的四个表及插入初始化数据
- java 执行jar_windows下如何用java指令运行jar包?
- firebird 3.0 开发者指南_11月19日召开 2020 vivo开发者大会报名正式开启
- 单片机串口发送数据很慢?这种方法帮助你提高!
- c语言教改课程项目,C语言程序设计课程的教学改革.pdf
- 电路常识性概念(8)-MOS管及简单CMOS逻辑门电路原理图
- 计算机显示有可移动存储,winxp系统中我的电脑出现很多个可移动磁盘怎么办
- java界面 ppt_Java GUI图形用户界面 课件.ppt
- 牛客练习赛46 C	华华跟奕奕玩游戏 (期望,概率)(详解)
- 第1节 IMPALA:4、5、linux磁盘的挂载和上传压缩包并解压