C#列表框、复选列表框、组合框的用法实例
2021-07-20 22:00
本文实例讲述了C#列表框、复选列表框、组合框的用法。分享给大家供大家参考。具体分析如下:
功能实现效果如下图所示:
实现代码:
1、声明相关变量存储专业、课程设置及相关信息:
代码如下:
string[] spec, cour1, cour2, cour3, cour4, cour5;
2、在Form1类中自定义函数bool checkGR()检查学生信息:
代码如下:
{
bool check = true;
if (textBox1.Text.Trim() == “” || textBox2.Text.Trim() == “”)
{
check = false;
MessageBox.Show(“姓名和年龄必须填写”);
}
return check;
}
3、在Form1类中自定义函数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 += “”;
}
}
if (hobby != “”)
{
hobby = “特长” + hobby;
}
gr += hobby;
gr += “.\n”;
xy = “所学专业.\n专业必修课程包括: “;
foreach (object course in listBox1.Items)
{
xy += “”;
}
xy += “。\n”;
if (checkedListBox1.CheckedItems.Count != 0)
{
xy += “特别说明:”;
foreach (object intr in checkedListBox1.CheckedItems)
{
xy += “”;
xy += “。”;
}
}
msg += gr + xy;
return msg;
}
C#列表框、复选列表框、组合框的用法实例
本文地址: http://www.paobuke.com/develop/c-develop/pbk23206.html