问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceStuMesFrm{publicpartialclassStuMesFrm:Form{publicStuMesFrm(){InitializeComponent();}privatevoidStuMesFrm_Load(objectsender,EventArgse){cboDept.SelectedIndex=0;//初始选择组合框的第一项dtBth.MaxDate=DateTime.Now;//设置出生日期最大值}privatevoidcboDept_SelectedIndexChanged(objectsender,EventArgse){switch(cboDept.SelectedIndex){case0:lstSpec.Items.Clear();lstSpec.Items.Add("计算机科学与技术");lstSpec.Items.Add("信息与计算科学");break;case1:lstSpec.Items.Clear();lstSpec.Items.Add("集成电路与集成系统");lstSpec.Items.Add("集成电路设计与集成系统");break;case2:lstSpec.Items.Clear();lstSpec.Items.Add("通信工程");lstSpec.Items.Add("电子信息工程");lstSpec.Items.Add("电磁场与无线技术");lstSpec.Items.Add("机械设计制造及其自动化");break;case3:lstSpec.Items.Clear();lstSpec.Items.Add("国际经济与贸易");lstSpec.Items.Add("电子商务");lstSpec.Items.Add("信息管理与信息系统");lstSpec.Items.Add("财务管理");break;default:lstSpec.Items.Clear();lstSpec.Items.Add("数字动画");lstSpec.Items.Add("影视动画");lstSpec.Items.Add("商用插画");break;};}privatevoidbtnYes_Click(objectsender,EventArgse){stringsex="";if(rdoBoy.Checked)sex=rdoBoy.Text;elsesex=rdoGirl.Text;stringdept;stringspec;dept=cboDept.SelectedItem.ToString();spec=lstSpec.SelectedItems.ToString();stringHobby="";if(checkBox1.Checked)Hobby+=checkBox1.Text;if(checkBox2.Checked)Hobby+=","+checkBox2.Text;if(checkBox3.Checked)Hobby+=","+checkBox3.Text;if(checkBox4.Checked)Hobby+=","+checkBox4.Text;if(checkBox5.Checked)Hobby+=","+checkBox5.Text;if(checkBox6.Checked)Hobby+=","+checkBox6.Text;stringinfo="你的姓名是:"+txtName.Text;info+="n性别为:"+sex;info+="n出生年月为:"+dtBth.Value.ToShortDateString();info+="n您是"+dept+"系"+spec+"专业的学生";info+="n你的兴趣有:"+Hobby;MessageBox.Show(info,"学生信息",MessageBoxButtons.OK,MessageBoxIcon.Information);}privatevoidbtnClose_Click(objectsender,EventArgse){this.Close();}privatevoidtimeGo_Tick(objectsender,EventArgse){if(lblTip.Left>=this.Width){lblTip.Left=0;}lblTip.Left+=1;}}}
解决方案
解决方案二:
你没有返回值,范回的是类型.你可以调试看看spec值是怎么得到的,在代码里没看到lstSpec的数据