今天用C#做的一个小的注册练习

下边是实现的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace Registerting
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
txtUserName.Enter += new EventHandler(txtUserName_Enter);
txtUserName.Leave += new EventHandler(txtUserName_Leave);
txtPassword.Enter += new EventHandler(txtUserName_Enter);
txtPassword.Leave += new EventHandler(txtPassWord_Leave);
txtPWConfirm.Enter += new EventHandler(txtPWConfirm_Enter);
txtPWConfirm.Leave += new EventHandler(txtPWConfirm_Leave);
txtMail.Enter += new EventHandler(txtMail_Enter);
txtMail.Leave += new EventHandler(txtMail_Leave);
chkAll.Enter += new EventHandler(chkAll_Enter);
chkAll.Leave += new EventHandler(chkAll_Leave);
}
/// <summary>
/// txtUserName(用户名)失去焦点事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtUserName_Leave(object sender, EventArgs e)
{
if (txtUserName.Text.Length < 1)
{
lblUNAttention.Visible = true;
lblUNAttention.Text = "用户名不能为空";
}
}
/// <summary>
/// txtUserName(用户名)获得焦点事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtUserName_Enter(object sender, EventArgs e)
{
if (txtUserName.Text.Length > 0)
{
lblUNAttention.Visible = false;
}
}
/// <summary>
/// txtPassWord(密码)失去焦点事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtPassWord_Leave(object sender, EventArgs e)
{
if ((0 < txtPassword.Text.Length) && (txtPassword.Text.Length < 6))
{
lblPasswordAttenton.Visible = true;
lblPasswordAttenton.Text = "密码不能少于六位";
}
else if (txtPassword.Text.Length < 1)
{
lblPasswordAttenton.Visible = true;
lblPasswordAttenton.Text = "密码不能为空";
}
}
/// <summary>
/// txtPassWord(密码)获得焦点事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtPassWord_Enter(object sender, EventArgs e)
{
if (txtUserName.Text.Length > 0)
{
lblUNAttention.Visible = false;
}
else
{
lblUNAttention.Visible = true;
}
lblPasswordAttenton.Visible = false;
}
/// <summary>
/// txtPWConfirm(密码)失去焦点事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtPWConfirm_Enter(object sender, EventArgs e)
{
if (txtUserName.Text.Length > 0)
{
lblUNAttention.Visible = false;
}
else
{
lblUNAttention.Visible = true;
}
if (txtPassword.Text.Length > 0)
{
lblPasswordAttenton.Visible = false;
}
else
{
lblPasswordAttenton.Visible = true;
}
}
/// <summary>
/// txtPWConfirm(密码)获得焦点事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtPWConfirm_Leave(object sender, EventArgs e)
{
if (txtPWConfirm.Text.Length < 1)
{
lblPWAttionC.Text = "确认密码输入不能为空";
lblPWAttionC.Visible = true;
}
else if (txtPWConfirm.Text != txtPassword.Text)
{
lblPWAttionC.Text = "两次密码输入不一致,\n请重新输入";
lblPWAttionC.Visible = true;
}
else if (txtPWConfirm.Text == txtPassword.Text)
{
lblPWAttionC.Visible = false;
}
}
private void txtMail_Enter(object sender, EventArgs e)
{
lblMAttion.Visible = false;
}
private void txtMail_Leave(object sender, EventArgs e)
{
string reg = @"^\s*([A-Za-z0-9_-]+(\.\w+)*@([\w-]+\.)+\w{2,10})\s*$";
if (txtMail.Text.Length < 1)
{
lblMAttion.Text = "邮箱输入不能为空";
lblMAttion.Visible = true;
}
else if (Regex.IsMatch(txtMail.Text, reg) == false)
{
lblMAttion.Text = "邮箱输入不合法";
lblMAttion.Visible = true;
}
}
private void chkAll_Enter(object sender, EventArgs e)
{
lblHobbyAttention.Visible = false;
}
private void chkAll_Leave(object sender, EventArgs e)
{
int sum = 0;
for (int i = 0; i < chklEate.Items.Count; i++)
{
if (chklEate.GetItemChecked(i) == true)
{
sum = sum + 1;
}
}
if (sum < 1)
{
lblHobbyAttention.Visible = true;
lblHobbyAttention.Text = "您还没有选择任何爱好";
}
}
/// <summary>
/// 全选或者全不选按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void chkAll_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < chklEate.Items.Count; i++)
{
if (chkAll.Checked == true)
{
//全选
chklEate.SetItemChecked(i, true);
}
else
{
//全不选
chklEate.SetItemChecked(i, false);
}
}
}
/// <summary>
/// 提交注册信息,如果注册信息都满足条件,那么提交成功,如果没有,则注册失败
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnRegister_Click(object sender, EventArgs e)
{
//邮箱的正则表达式
string reg = @"^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$";
int sum = 0;
//计算选择的爱好数目
for (int i = 0; i < chklEate.Items.Count; i++)
{
if (chklEate.GetItemChecked(i) == true)
{
sum = sum + 1;
}
}
//判断注册的所有信息是否合法,合法就注册成功,并关闭窗口
if ((txtUserName.Text.Length > 0) && (txtPassword.Text.Length > 5) && (txtPassword.Text == txtPWConfirm.Text) && (Regex.IsMatch(txtMail.Text, reg) == true) && (sum > 0))
{
DialogResult dr = MessageBox.Show("您注册成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (dr == DialogResult.OK)
{
this.Close();
}
}
else
{
MessageBox.Show("您注册失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// 清空输入信息和提示信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnConcel_Click(object sender, EventArgs e)
{
txtUserName.Clear();
lblUNAttention.Text = "";
txtPassword.Clear();
lblPasswordAttenton.Text = "";
txtPWConfirm.Clear();
lblPWAttionC.Text = "";
txtMail.Clear();
lblMAttion.Text = "";
chklEate.ClearSelected();
lblHobbyAttention.Text = "";
chkAll.Checked = false;
}
}
}
今天用C#做的一个小的注册练习的更多相关文章
- FMX相当于在界面上自己又做了一个小操作系统
FMX的自画界面我也不看好,比如复制粘贴,太丑了,系统做得很好很精细的复制粘贴界面,就是无法调出,比如MIUI,复制粘贴还能有个放大镜,可以选择到屏幕边缘的文字,可以选择剪贴板内多个可粘贴的文字:还有 ...
- DOM的利用冒泡做的一个小程序
我们都知道DOM的事件流,有冒泡事件,如何有效的利用冒泡? 优化:应该尽量少的添加事件监听:原理:每添加一个事件监听事件,就会在浏览器中添加一个EventListener,如果数量过多,浏览器只能一个 ...
- 加班两个星期做的一个小系统~(winform)
不管怎么样~加班两个星期,单独一人,努力将公司需要用的系统给做出来了,也感谢提供技术帮助的可爱人儿~ 首先,系统有个检测版本的功能,若版本不是最新的,则会自动更新(公司要求,必须强制更新)~ 更新界面 ...
- 基于Tkinter以及百度翻译爬虫做的一个小的翻译软件
首先看效果: 输入Hello, 可见输出 int. 打招呼 下面看源码: from tkinter import * import requests# 首先导入用到的库 request = reque ...
- 对于xss等有关的html,url,unicode编码做的一个小总结。
参考:http://bobao.360.cn/learning/detail/292.html,算是对前部分作一个总结性的学习. 1<a href="%6a%61%76%61%73%6 ...
- Angularjs做的一个小页面
<!DOCTYPE html><html lang="en" ng-app="todolist"> <head> <m ...
- 自己做的一个小demo
上图: 主段代码: <script type="text/javascript"> var getRandomColor = function(){ return (f ...
- 用Unity做的一个小游戏,仿照一个样例写的,个人认为文章写的不错,哈哈
- jquery做一个小的轮播插件---有BUG,后续修改
//首页无缝轮播 ; (function($, window, document, undefined) { $.fn.slider = function(options) { var default ...
随机推荐
- dp related problems (update continuously)
Leetcode Maximum Product Subarray 这个问题是说给一个整数数组.求最大连续子阵列产品. 纠结了包括阵列中的很长一段时间0而如何处理负数,关键的事实是,负治疗,所以我们录 ...
- java 突击队注意事项:在路上
情绪: 灵活:让标准成为价格值.为了给你一个想法和标准,你可以有一个不同的使用.不是死扣定理.决这个问题. 看书:分两类,一类依据知识点进行罗列.并且结构清晰,能够看完一章有选择进行总结(不是笔记,总 ...
- Echarts Jqplot嵌extjs4 windows 装配方法
js组件绘图终于是画在一个指定id的div或dom元素中. 在项目中有可能须要画在 Extjs容器中,研究了一下,能够通过下面的思路实现,方法跟大家共享下: 1.首先做一个容器,把此内容加入到wind ...
- sqlplus登录问题
问题1.sqlplus login -- SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory 在/e ...
- redis权限认证(设置密码)的方法
redis可以通过设置密码来增强安全强度.除了设置密码,我们还可以通过修改redis的默认端口.对端口做防火墙等.那么如何开启redis的密码功能呢?以下就是详细的步骤方法: 打开redis.conf ...
- Tyvj P1016 包装问题 (DP)
底 Background 太原诚成中学2模拟法庭竞赛 第三条道路 描写叙述 Description 有一个箱子容量为v(正整数.o≤v≤20000).同一时候有n个物品(o≤n≤30).每一个物品有一 ...
- 文《左右c++与java中国的垃圾问题的分析与解决》一bug分析
文<左右c++与java中国的垃圾问题的分析与解决>一bug分析 DionysosLai(906391500@qq.com) 2014/10/21 在前几篇一博客<关于c++与jav ...
- csu 1503: 点弧之间的距离-湖南省第十届大学生计算机程序设计大赛
这是--比量p并用交点连接中心不上弧.在于:它至p距离.是不是p与端点之间的最短距离 #include<iostream> #include<map> #include< ...
- CSS3+HTML5特效6 - 闪烁的文字
先看效果 abcd 这个效果也比较简单,利用keyframes对文字的大小.透明度及颜色做循环显示. CSS <style> @-webkit-keyframes flash { 0%{ ...
- Socket 学习(三)
前2节,说的是 Server 与 Client 的数据交互.服务端IP.端口固定,客户端 网服务端发送消息的时候,他的Socket对面被服务端获取到了,而且链接没有中断,他当然可以很容易回复信息. 现 ...