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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
參照
namespace _103303058_0413_02
{

class CPerson
{
public string Name = "請輸入";
private double m_Weight ;
private double m_Height ;

public double Weight
{
get { return m_Weight; }
set
{
if (value >= 300) { value = 300; }
else if (value <= 0) { value = 0; }
else { m_Weight = value; }
}
}

public double Height
{
get { return m_Height; }
set
{
if (value >= 250) { value = 250; }
else if (value <= 0) { value = 0; }
else { m_Height = value; }
}
}
}
}


設計者
/// <summary>
/// 設計工具所需的變數。
private CPerson Wang;
/// </summary>



namespace _103303058_0413_02
{


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

}

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://zh.wikipedia.org/wiki/%E7%8E%8B%E5%BB%BA%E6%B0%91_%28%E6%A3%92%E7%90%83%E9%81%B8%E6%89%8B%29");
}

private void button1_Click(object sender, EventArgs e)
{


double BMI;

Wang.Height = Convert.ToDouble(maskedTextBox1.Text)/100;
Wang.Weight = Convert.ToDouble(maskedTextBox2.Text);
BMI = Wang.Weight / (Wang.Height * Wang.Height);
textBox4.Text = BMI.ToString();

if (BMI < 18.5)
{
MessageBox.Show("過輕", "MsgBox", MessageBoxButtons.YesNoCancel);
}
if (BMI >= 18.5 && BMI < 24)
{
MessageBox.Show("正常", "MsgBox", MessageBoxButtons.YesNoCancel);
}
if (BMI < 27 && BMI >= 24)
{
MessageBox.Show("過重", "MsgBox", MessageBoxButtons.YesNoCancel);
}
if (BMI < 30 && BMI >=27)
{
MessageBox.Show("輕度肥胖", "MsgBox", MessageBoxButtons.YesNoCancel);
}
if (BMI < 35 && BMI>=30)
{
MessageBox.Show("中度肥胖", "MsgBox", MessageBoxButtons.YesNoCancel);
}
if (BMI >=35)
{
MessageBox.Show("重度肥胖", "MsgBox", MessageBoxButtons.YesNoCancel);
}


}

private void Form1_Load(object sender, EventArgs e)
{
Wang = new CPerson();
radioButton1.Checked = true;


comboBox1.Text = "西元年";
comboBox2.Text = "月";
comboBox3.Text = "日";
for(int k = 1960; k<=2015; k ++)
{
comboBox1.Items.Add(k);
}
for (int k = 1; k <= 12; k++)
{
comboBox2.Items.Add(k);
}
for (int k = 1; k <= 31; k++)
{
comboBox3.Items.Add(k);
}

textBox1.Text = Wang.Name;
maskedTextBox1.Text = "90";
maskedTextBox2.Text = "190";
}

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

if (comboBox1.SelectedIndex == -1)
{
MessageBox.Show("請選擇你的出生年", "錯誤", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else if (comboBox2.SelectedIndex == -1)
{
MessageBox.Show("請選擇你的出生月", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (comboBox3.SelectedIndex == -1)
{
MessageBox.Show("請選擇你的出生日", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
str = "你的生日是西元" + comboBox1.SelectedItem.ToString() + "年" + comboBox2.SelectedItem.ToString() + "月" + comboBox3.SelectedItem.ToString() + "日";

if(checkBox1.Checked == false && checkBox2.Checked ==false && checkBox3.Checked == false)
{
str += "\n而你不喜歡任何運動";
}
else
{
str += "\n而你喜歡的運動是";
}

if (checkBox1.Checked == true) {str += " 棒球";}
if (checkBox2.Checked == true) {str += " 藍球";}
if (checkBox3.Checked == true) {str += " 族球";}


MessageBox.Show(str, "生日");
}
}

}
}