WinForm小程序(技术改变世界-cnblog)

 

需求:

1.点击按钮  更新 当前时间

2.输入 身份证,必须身份证 排序(类似银行卡那样的空格),自动生成空格排序

3.实现 必须按 第一个按钮,第三个按钮才可以使用

4.判断身份证 输入 必须 除 最后一个数可以为X外,其他都必须是数字

5.在LISTBOX输出 这个身份证者的 出生年份和 生日

6.当使用者是成年人可以浏览 隐藏的图片,否则不可以

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; namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} string[] strs; private void Form1_Load(object sender, EventArgs e)
{
//textBox1.ReadOnly = false;//这是 显示,并可以输入,但是输入无效
//textBox1.Enabled = false;//同下
button3.Enabled = false;//是显示了,不可以使用点击
//button3.Visible = false;// 在窗体不显示
label2.Text = string.Empty;
panel1.Visible = false;
} private void button1_Click(object sender, EventArgs e)
{
button3.Enabled = true;
label2.Text = DateTime.Now.ToLocalTime().ToString() ; } private void button2_Click(object sender, EventArgs e)
{ strs = textBox1.Text.Split(' '); //判断正确性
for (int i = 0; i < strs.Length-1; i++)//为什么长度-1,因为有的人身份证最后位是X
{
int temp;
if (int.TryParse(strs[i], out temp) == false)
{
MessageBox.Show(string.Format("您输入的第{0}组数有误",++i));
return;
}
} listBox1.Items.Clear();//防止多次按确认
listBox1.Items.Add(string.Format("您的年份是:{0}年",strs[1])); listBox1.Items.Add(string.Format("您的生日是:{0}月{1}日",strs[2].Substring(0,2),strs[2].Substring(2,2)));
textBox1.Clear();
} private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
//判断光标的位置
if (textBox1.SelectionStart==6)
{
textBox1.Text += " ";
textBox1.SelectionStart = 8;
return;
}
if (textBox1.SelectionStart == 11)
{
textBox1.Text += " ";
textBox1.SelectionStart = 13;
return;
}
if (textBox1.SelectionStart == 16)
{
textBox1.Text += " ";
textBox1.SelectionStart = 18;
return;
}
if (textBox1.SelectionStart == 21)//只能输入21-3(空格)=18位身份证
{
e.Handled = true;
}
} private void button3_Click(object sender, EventArgs e)
{
//未满18岁禁止查看
pictureBox1.Image = imageList1.Images[0];
int i1;
int i2=int.Parse(strs[1]);
if (int.TryParse(label2.Text.Substring(0, 4), out i1))
{
if ((i1 - i2) >= 18)
{
panel1.Show();
}
else
{
MessageBox.Show("你未满18岁,不可以查看","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
}
} }
}
}
 
 
分类: WinForm
 
 

最新文章

  1. ASP.NET MVC Model验证(三)
  2. 三种常用的MySQL建表语句(转)
  3. java筛选法求素数
  4. HDU5072 容斥原理
  5. 【转】设计模式(三)建造者模式Builder(创建型)
  6. Event 讲解
  7. cisco VPN
  8. Enumeration 接口
  9. angular模板加载 ----ng-template
  10. mac skim 修改背景色
  11. 利用Xilinx中的ROM构造查找表来计算sin和cos的方法探讨
  12. 强行在MFC窗体中渲染Cocos2d-x 3.6
  13. 201521123076 《Java程序设计》第10周学习总结
  14. Django 模版中如何对主菜单进行选中?
  15. Consecutive Sum LightOJ - 1269(区间异或和)
  16. 用python写栈
  17. Eclipse插件:Spket
  18. 推荐:7 月份值得一看的 Java 技术干货!
  19. A2D JS框架 - AOP封装
  20. C# winform C/S WebBrowser qq第三方授权登录

热门文章

  1. Android FrameWork 学习之Android 系统源码调试
  2. Hive扩展功能(五)--HiveServer2服务高可用
  3. ASP.NET 缓存(Cache)
  4. python调用java API
  5. VC++ 遍历文件夹
  6. Windows2008 Server 常规设置及基本安全策略
  7. (转) Hibernate检索方式概述
  8. python利用7z批量解压rar
  9. vue 使用echarts
  10. Maven学习总结(27)——Maven自定义打包插件maven-assembly-plugin详解