4.c#winform basic picture (show and hide)

Source: Internet
Author: User

Requirements:

There is a picture on the software, which is hidden by default. The user enters a social Security number (131226198105223452) in the text box, clicks the button, and displays the picture if it is older than 18 years old.

Knowledge Points:

take the current year, Date time
The function that needs to be

function One:                        

String string. Substring (int startindex,int length) (+1 overloads)
Retrieves a string from this instance. SUBSTRING starts at the specified character position and has the specified length
Abnormal:
System.ArgumentOutOfRangeException

Function Two:

           int Convert.ToInt32 (string value) (+18 overloads)    
            the designation of the number The System.String representation is converted to an equivalent 32-bit signed integer
                Exceptions:
                       System.FormatException
                       system.overflowexception

Function Three:
struct System.DateTime
represents a moment in time, usually expressed as a date and time of day.

The source code is as follows:

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespacePicture Display { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        Private voidButton1_Click (Objectsender, EventArgs e) {            stringID Number =TextBox1.Text; /*string String. Substring (int startindex,int length) (+1 overloads) * Retrieves a string from this instance.             The substring starts at the specified character position and has the specified length * Exception: * system.argumentoutofrangeexception */            stringStryear= ID number. Substring (6,4); /*int Convert.ToInt32 (string value) (+18 overloads) * Converts the specified System.String representation of a number to an equivalent 32-bit signed integer * exception: * System.FormatException * System.OverflowException*/            intYear =Convert.ToInt32 (stryear); /*struct System.DateTime * Represents a moment in time, usually expressed as a date and time of day. */                        if(Datetime.now.year-year > -) {picturebox1.visible=true; }            Else{picturebox1.visible=false; }        }    }}

Run:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.