27,579
社区成员
发帖
与我相关
我的任务
分享
//判断闰年
private bool checkleap(int year)
{
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
return true;
else return false;
}
//绑定每月的天数
private void binddays(int year, int month)
{
int i;
ArrayList alday = new ArrayList();
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
for (i = 1; i <= 31; i++)
alday.Add(i);
break;
case 2:
if (checkleap(year))
{
for (i = 1; i <= 29; i++)
alday.Add(i);
}
else
{
for (i = 1; i <= 28; i++)
alday.Add(i);
}
break;
case 4:
case 6:
case 9:
case 11:
for (i = 1; i <= 30; i++)
alday.Add(i);
break;
}
this.comboBox3.DataSource = alday;
}
private void Form1_Load(object sender, EventArgs e)
{
//绑定年
ArrayList alyear = new ArrayList();
int i;
for (i = 1900; i <= 2099; i++)
alyear.Add(i);
this.comboBox1.DataSource = alyear;
//绑定月
ArrayList almonth = new ArrayList();
for (i = 1; i <= 12; i++)
almonth.Add(i);
this.comboBox2.DataSource = almonth;
int year, month;
year = Int32.Parse(this.comboBox1.SelectedValue.ToString());
month = Int32.Parse(this.comboBox2.SelectedValue.ToString());
binddays(year, month);//绑定天
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int year, month;
year = Int32.Parse(this.comboBox1.SelectedValue.ToString());
month = 1;
binddays(year, month);
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
int year, month;
year = Int32.Parse(this.comboBox1.SelectedValue.ToString());
month = Int32.Parse(this.comboBox2.SelectedValue.ToString());
binddays(year, month);
}