日期:2014-05-17 浏览次数:20955 次
功能实现效果:
实现代码:
1>声明相关变量存储专业、课程设置及相关信息:
string gr, msg, xy; string[] spec, cour1, cour2, cour3, cour4, cour5;
2>在Form1类中自定义函数bool
checkGR()检查学生信息:
private bool checkGR() { bool check = true; if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "") { check = false; MessageBox.Show("姓名和年龄必须填写"); } return check; }
3>在Form1类中自定义函数string
record()收集学生信息:
private string record() { gr = ""; gr += textBox1.Text.Trim(); if (radioButton1.Checked) gr += ",男"; else gr += ",女"; gr += "," + textBox2.Text.Trim() + "岁,"; string hobby = ""; foreach (Control ct1 in groupBox1.Controls) { CheckBox chk=(CheckBox)ct1; if (chk.Checked == true) { hobby += "<" + chk.Text + ">"; } } if (hobby != "") { hobby = "特长" + hobby; } gr += hobby; gr += ".\n"; xy = "所学专业<" + comboBox1.Text+">.\n专业必修课程包括: "; foreach (object course in listBox1.Items) { xy += "<" + course.ToString() + ">"; } xy += "。\n"; if (checkedListBox1.CheckedItems.Count != 0) { xy += "特别说明:"; foreach (object intr in checkedListBox1.CheckedItems) { xy += "<" + intr.ToString() + ">"; xy += "。";