您的位置:首页 > 移动开发 > 微信开发

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

  • 点赞
  • 收藏
  • 分享
  • 文章举报
amenfu7203 发布了0 篇原创文章 · 获赞 0 · 访问量 588 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐