窗体加载,判断年份。

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 yearDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {

            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            String text = textBox2.Text;
            int year = Convert.ToInt32(text);

            //添加
            listBox1.Items.Add(year);


        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            /* int j = 0;
             int a = Convert.ToInt32(comboBox1.Text);
             int b = Convert.ToInt32(comboBox2.Text);
             object[] c = new object[100];
             if (a > b)
             {
                 MessageBox.Show("起始年份不能大于终止年份", "错误提示");
                 return;
             }
             for (int i = a; i <= b; i++)
             {
                 if (yearPd(i))
                 {
                     c[j] = i.ToString();
                     j++;
                 }
             }
             listBox1.DataSource = c;
             * made by ws
             * */
            listBox1.Items.Clear();
            int i = 0;
            int a = Convert.ToInt32(comboBox1.Text);
            int b = Convert.ToInt32(comboBox2.Text);
            if (a > b)
            {
                MessageBox.Show("起始年份比结束年份多!");
            }
            else
            {
                for (i = a; i <= b; i++)
                {
                    listBox1.Items.Add(i);
                }
            }

        }

        public Boolean yearPd(int year)
        {
            int i = year;
            if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
            {
                return true;
            }
            return false;

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (listBox1.Items.Count > 0)
            {   //清空

                listBox1.Items.Clear();
                /*
                object[] c = new object[100];
                listBox1.DataSource = c;
                 * * made by ws
                 * */
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button8_Click(object sender, EventArgs e)
        {
            //读取下标
            int i = this.listBox1.SelectedIndex;
            String text = textBox2.Text;
            if (i >= 0)
            {
                //添加
                listBox1.Items.Insert(i + 1, text);
            }
            else
            {
                listBox1.Items.Add(text);
            }

        }

        private void button7_Click(object sender, EventArgs e)
        {
            label5.Text = null;
            int i = this.listBox1.SelectedIndex;
            if (i >= 0)
            {
                //移除选定的数据
                listBox1.Items.RemoveAt(i);
                i = -1;
            }
            else
            {
                MessageBox.Show("未选中年份!");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //【判断是否闰年】
            String year = listBox1.SelectedItem.ToString();
            int y = Convert.ToInt32(year);
            if (yearPd(y))
            {
                label5.Text = y + "是闰年";
            }
            else
            {
                label5.Text = y + "是平年";
            }
        }

    }
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值