黑马程序员之WinForm编程基础学习笔记:页面上有一张图片,默认是隐藏的,用户在文本框中输入身份证号(131226198105223452),点击按钮,如果年龄大于18岁则显示图片。

时间:2022-04-05 09:15:03

--------------------------------------------------- 2345王牌技术员联盟2345王牌技术员联盟、期待与您交流!---------------------------------------------------------

using System.Collections.Generic;

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Test4
{
      public partial calss Form1 : Form
      {
            public Form1()
            {
                   InitialzeComponent();
            }
            private void button1_Click(object sender, EventArgs e)
            {
                       string 身份证号 = textBox1.Text;
                       //检验是否是合法的身份证号,不考虑X
                       //131226198105223452
                       pictureBox1.Visible = false;
                       string strYear = 身份证号.Substring(6,4);
                       int year = Convert.ToInt32(strYear);
                       if(DateTime.Now.Year - year > 18)
                       {
                              pictureBox1.Visible = true;
                       }

            }
      }

}


--------------------------------------------------- 2345王牌技术员联盟2345王牌技术员联盟、期待与您交流!---------------------------------------------------------