zoukankan      html  css  js  c++  java
  • C# WinForm小程序(技术改变世界-cnblog)

    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);
    }
    }


    }
    }
    }
    复制代码



     
     
  • 相关阅读:
    nodejs gulp如何获取参数
    nodejs 获取当前路径的方法
    gulp 如何排除文件和文件夹
    小技巧css解决移动端ios不兼容position:fixed属性,无需插件
    代码协议相关
    zen-coding
    directive 实例讲解
    angular api 地址
    一步一步搭建hibernate4+ spring+ struts2
    华为荣耀6 H60-L02/L12(联通版)救砖包【适用于无限重启】
  • 原文地址:https://www.cnblogs.com/meimao5211/p/3334198.html
Copyright © 2011-2022 走看看