zoukankan      html  css  js  c++  java
  • 4.C#WinForm基础图片(显示和隐藏)

    要求:

    软件上有一张图片,默认是隐藏的。用户在文本框中输入身份证号(131226198105223452),点击按钮,如果年龄大于18岁,则显示图片。

    知识点:

     取当前年份,Date Time Now Year
    所需用到的函数

    函数一:                       

              string string.Substring(int startIndex,int length)(+1重载)
                    从此实例检索字符串。子字符串从指定的字符位置开始且具有指定的长度
              异常:
                          System.ArgumentOutOfRangeException

    函数二:

              int Convert.toInt32(string value)(+18重载)   
                将数字的指定 System.String 表示形式转换为等效的32位有符号整数
                   异常:
                          System.FormatException
                          System.OverflowException

    函数三:
                                  struct System.DateTime
                      表示时间的一刻,通常以日期和当天的时间表示。        

    源码如下:

    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 图片显示
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string 身份证号 = textBox1.Text; 
      
                /* string string.Substring(int startIndex,int length)(+1重载)
                 * 从此实例检索字符串。子字符串从指定的字符位置开始且具有指定的长度
                 * 
                 * 异常:
                 *       System.ArgumentOutOfRangeException
                 */
                string strYear=身份证号.Substring(6,4);
    
    
                /* int Convert.toInt32(string value)(+18重载)   
                 * 将数字的指定 System.String 表示形式转换为等效的32位有符号整数
                 * 异常:
                 *        System.FormatException
                 *        System.OverflowException
                 */
    
                int year = Convert.ToInt32(strYear);
             
                /*  struct System.DateTime
                 * 表示时间的一刻,通常以日期和当天的时间表示。
                 */
                
                if (DateTime.Now.Year - year > 18)
                {
                    pictureBox1.Visible = true;
                }
                else 
                {
                    pictureBox1.Visible = false;
                }
            }
        }
    }

    运行截图:

  • 相关阅读:
    MathML
    Redux counterpart rematch dva
    flow
    pauseable 库
    a simple machine learning system demo, for ML study.
    react图工具集成
    SQLite
    Celery
    RabbitMQ installation
    Thunk
  • 原文地址:https://www.cnblogs.com/xingyunblog/p/3888818.html
Copyright © 2011-2022 走看看