求窗口问题!goto用法
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WanNianLi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnJiSuan_Click(object sender, EventArgs e)
{
int y, m, d, sum;
y = int.Parse(txtYear.Text);
m = int.Parse(txtMonth.Text);
d = int.Parse(txtDays.Text);
if (y < 1 || y > 9999)
{
txtXianShi.Text = "你输入的年份不正确!请重新输入!";
txtYear.Text = "";
txtYear.Focus();
}
else if (m < 1 || m > 12)
{
txtXianShi.Text = "你输入的月份不正确!请重新输入!";
txtMonth.Text = "";
txtMonth.Focus();
}
else {
switch (m) {
case 2:
if ((y % 100 != 0 && y % 4 == 0) || (y % 400 == 0)) {
if (d < 1 || d > 29) {
txtXianShi.Text = "你输入的天数不正确!请重新输入!";
txtDays.Text = "";
txtDays.Focus();
}
} break;
case 4:case 6:case 9:case 11:
if (d < 1 || d > 30) {
txtXianShi.Text = "";
txtDays.Text = "";
txtDays.Focus();
} break;
default:
if (d < 1 || d > 31) {
txtXianShi.Text = "你输入的天数不正确!请重新输入!";
txtDays.Text = "";
txtDays.Focus();
}
break;
}
if (m == 1 || m == 2) {
sum = (m - 1) * 31 + d; }
else {
switch (m) {
case 9:case 11:
sum = (m - 1) * 30 + d - 2 + m / 2 + 1;
break;
default:
sum = (m - 1) * 30 + d - 2 + m / 2;
break;
} if ((y % 100 != 0 && y % 4 == 0) || (y % 400 == 0)) {
sum = sum + 1;
}
txtXianShi.Text = y + "年" + m + "月" + d + "日是" + y + "年的第" + sum + "天";
}
}
}
}
}
WanNianLi.rar
(33.12 KB)
goto方法不会用,知道怎么用,还有其他更好的办法来