zoukankan      html  css  js  c++  java
  • 计算闰年_winform

    新建窗体应用程序(如下),新建控件label1,label2,label3,textBOX1,button1,button2

    label1的Text属性改为“计算闰年演示”

    label2的Text属性改为“输入年份”

    button1的Text属性改为“确定”

    button1的Text属性改为“退出”

    完整代码:

     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Threading.Tasks;
     9 using System.Windows.Forms;
    10 
    11 namespace 计算闰年_窗体
    12 {
    13     public partial class Form1 : Form
    14     {
    15         //闰年:能被4整除,但不能被100整除或者能被400整除的年份
    16         public Form1()
    17         {
    18             InitializeComponent();
    19         }
    20 
    21         private void button2_Click(object sender, EventArgs e)//退出按钮代码
    22         {
    23             Application.Exit();
    24         }
    25 
    26         private void button1_Click(object sender, EventArgs e)//确定按钮代码
    27         {
    28             try
    29             {
    30                 int year = Convert.ToInt32(textBox1.Text);
    31                 if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0)//闰年:能被4整除,但不能被100整除或者能被400整除的年份
    32                 {
    33                     label3.Text = string.Format("{0}是闰年", year);//输出显示闰年
    34                 }
    35                 else
    36                 {
    37                     label3.Text = string.Format("{0}不是闰年", year);//输出显示非闰年
    38                 }
    39             }
    40             catch
    41             {
    42                 MessageBox.Show("请输入正确年份");
    43             }
    44         }
    45     }
    46 }
  • 相关阅读:
    I2S波形解析
    F407整点原子I2C波形解码
    WAVE格式文件说明
    ADC结构体初始化成员
    这次,我是真的想吐槽MDK
    I2S源程序(正点原子F407探索者)
    强制类型转换
    嵌套结构体的初始化
    lua 元方法 __index
    lua pairs 与 ipairs
  • 原文地址:https://www.cnblogs.com/start-from-scratch/p/5046524.html
Copyright © 2011-2022 走看看