男”; else gr += “

时间:2021-07-14 07:53:32

成果实现效果如下图所示:

男”; else gr += “

男”; else gr += “

实现代码:

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 += “。”;

}

}

msg += gr + xy;

return msg;

}