1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/// <summary>
/// 設計工具所需的變數。
/// </summary>
private System.ComponentModel.IContainer components = null;
private Sports FavoriteSport;
/// <summary>

namespace _103303058_0427_01
{

enum Sports
{
Football,
Baseball,
Basketball
};

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void label3_Click(object sender, EventArgs e)
{

}

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if(checkBox1.Checked == true)
{
panel2.Enabled = true;
}
else
{
panel2.Enabled = false;
}
}

private void Form1_Load(object sender, EventArgs e)
{
FavoriteSport = Sports.Football;
radioButton_Football.Checked = true;
comboBoxYear.Text = comboBoxMonth.Text = comboBoxDate.Text = "請選擇";
for(int i = 1960; i<=2015; i++)
{
comboBoxYear.Items.Add(i);
}
for(int i = 1; i<=12; i++)
{
comboBoxMonth.Items.Add(i);
}
for (int i = 1; i <= 31; i++)
{
comboBoxDate.Items.Add(i);
}
}

private void radioButton_Baseball_CheckedChanged(object sender, EventArgs e)
{
FavoriteSport = Sports.Baseball;
}

private void radioButton_basketball_CheckedChanged(object sender, EventArgs e)
{
FavoriteSport = Sports.Basketball;
}

private void button1_Click(object sender, EventArgs e)
{
String str;

if (comboBoxYear.SelectedIndex == -1)
{
MessageBox.Show("請選擇你的出生年", "錯誤", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else if (comboBoxMonth.SelectedIndex == -1)
{
MessageBox.Show("請選擇你的出生月", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (comboBoxDate.SelectedIndex == -1)
{
MessageBox.Show("請選擇你的出生日", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
str = "你的生日是西元" + comboBoxYear.SelectedItem.ToString() + "年" + comboBoxMonth.SelectedItem.ToString() + "月" + comboBoxDate.SelectedItem.ToString() + "日";
if (checkBox1.Checked)
{
str = str + "\n而你最喜歡的運動是";
switch (FavoriteSport)
{
case Sports.Baseball:
str += "棒球";
break;
case Sports.Football:
str += "足球";
break;
case Sports.Basketball:
str += "籃球";
break;
}
}
MessageBox.Show(str, "生日");
}
}
}
}