第三节 4练习2

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 _4练习2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string str = tb.Text;
            //判断身份证号是否合法
            for (int i = 0; i < str.Length; i++) 
            {
                string ca = Convert.ToString(str[i]);
                int ii;
                if (!int.TryParse(ca, out ii)) {
                    MessageBox.Show("身份证数据不合法!");
                    return;
                }
            }

            //取年龄数
            string strYear = str.Substring(6,4);
            int year = Convert.ToInt32(strYear);
            MessageBox.Show("year="+year);
            //131226198105223452
            if (DateTime.Now.Year - year >= 18)
            {
                pictureBox1.Visible = true;
                return;
            }
            else {
                pictureBox1.Visible = false;
                MessageBox.Show("未满十八岁!");
                return;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string str = tb_keyword.Text;
            string firstStr = Convert.ToString(str[0]);
            string endStr = str.Substring(1);
            tb_keyword.Text = endStr + firstStr;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string str = tb_keyword.Text;
            int t = str.Length - 1;
            string endStr = Convert.ToString(str[t]);

            //操,这里的长度和索引值还
            string firstStr = str.Substring(0,t);
            tb_keyword.Text = endStr + firstStr;
        }
    }
}

  

你可能感兴趣的:(第三节 4练习2)