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 + "是平年";
}
}
}
}