Calculate leap Year _winform

Source: Internet
Author: User

Create a new Form application (below) and create a new control Label1,label2,label3,textbox1,button1,button2

Change the Text property of Label1 to "Calculate Leap year Demo"

Change the Text property of Label2 to "enter year"

Change the Text property of button1 to "OK"

Change the Text property of button1 to "exit"

Full code:

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Threading.Tasks;9 usingSystem.Windows.Forms;Ten  One namespaceCalculate leap Year _ form A { -      Public Partial classForm1:form -     { the         //leap Year: Years that can be divisible by 4, but not divisible by 100 or divisible by 400 -          PublicForm1 () -         { - InitializeComponent (); +         } -  +         Private voidButton2_Click (Objectsender, EventArgs e)//Exit button Code A         { at application.exit (); -         } -  -         Private voidButton1_Click (Objectsender, EventArgs e)//Determine the button code -         { -             Try in             { -                 intYear =Convert.ToInt32 (TextBox1.Text); to                 if(Year% -==0|| Year%4==0&& Year% -!=0)//leap Year: Years that can be divisible by 4, but not divisible by 100 or divisible by 400 +                 { -Label3. Text =string. Format ("{0} is a leap year", year);//output shows leap year the                 } *                 Else $                 {Panax NotoginsengLabel3. Text =string. Format ("{0} is not a leap year", year);//output shows non-leap years -                 } the             } +             Catch A             { theMessageBox.Show ("Please enter the correct year"); +             } -         } $     } $}

Calculate leap Year _winform

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.