您的位置:首页 > 其它

计算闰年_winform

2015-12-14 20:54 435 查看
新建窗体应用程序(如下),新建控件label1,label2,label3,textBOX1,button1,button2



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

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

button1的Text属性改为“确定”

button1的Text属性改为“退出”



完整代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 计算闰年_窗体
{
public partial class Form1 : Form
{
//闰年:能被4整除,但不能被100整除或者能被400整除的年份
public Form1()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)//退出按钮代码
{
Application.Exit();
}

private void button1_Click(object sender, EventArgs e)//确定按钮代码
{
try
{
int year = Convert.ToInt32(textBox1.Text);
if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0)//闰年:能被4整除,但不能被100整除或者能被400整除的年份
{
label3.Text = string.Format("{0}是闰年", year);//输出显示闰年
}
else
{
label3.Text = string.Format("{0}不是闰年", year);//输出显示非闰年
}
}
catch
{
MessageBox.Show("请输入正确年份");
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: