WinForm小程序(技术改变世界-cnblog)
2020-04-04 18:31
1166 查看
需求:
1.点击按钮 更新 当前时间
2.输入 身份证,必须身份证 排序(类似银行卡那样的空格),自动生成空格排序
3.实现 必须按 第一个按钮,第三个按钮才可以使用
4.判断身份证 输入 必须 除 最后一个数可以为X外,其他都必须是数字
5.在LISTBOX输出 这个身份证者的 出生年份和 生日
6.当使用者是成年人可以浏览 隐藏的图片,否则不可以
View Code
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);
}
}
}
}
}
转载于:https://www.cnblogs.com/IAmBetter/archive/2012/01/12/2321078.html
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- C# WinForm小程序(技术改变世界-cnblog)
- WinForm小程序(技术改变世界-cnblog)
- 若对File与Directory类陌生-我们一起学习 Winform界面(技术改变世界-cnblog)
- C# WINFORM 局域网PING 工具(技术改变世界-cnblog)
- 再谈后兵 FileInfo 与 DirectoryInfo类 清晰的winform界面(技术改变世界-cnblog)
- WINFORM 局域网PING 工具(技术改变世界-cnblog)
- 数据流的所有类 ---Winform界面 (技术改变世界-cnblog)
- WINFORM 局域网PING 工具(技术改变世界-cnblog)
- 数据流的所有类 ---Winform界面 (技术改变世界-cnblog)
- 若对File与Directory类陌生-我们一起学习 Winform界面(技术改变世界-cnblog)
- winform设计一个登录界面和修改密码的界面-自动切换窗体(问题[已解] 望一起讨论)(技术改变世界-cnblog)
- winform设计一个登录界面和修改密码的界面-自动切换窗体(问题[已解] 望一起讨论)(技术改变世界-cnblog)
- 再谈后兵 FileInfo 与 DirectoryInfo类 清晰的winform界面(技术改变世界-cnblog)
- 以一个 山寨 资源管理器 结束 file类与Directory类 (技术改变世界-cnblog)
- Button按钮实现 向左或向右 缩进字符并显示在首部(尾部)(技术改变世界-cnblog)
- 以一个 山寨 资源管理器 结束 file类与Directory类 (技术改变世界-cnblog)
- “让技术改变世界”,更要用技术打造中国的国际化!-写过园子里面一些类似Nbear的团队和一切承认自己是中国人的人!~
- 关于2018年 九大改变世界的技术趋势
- 改变世界的硬件加速技术
- 以太坊社区激励金计划:支持开发者利用去中心化技术改变世界