基于《C#中switch选择语句配合下拉列表控件完成季节判断与窗体颜色变化》视频讲解源代码:
设计界面:
季节判断与窗体背景颜色变化
季节判断:
private void button1_Click(object sender, EventArgs e)
{
switch(comboBox1.SelectedIndex 1)
{
case 3:
case 4:
case 5:
textBox1.Text = "春季";
break;
case 6:
case 7:
case 8:
textBox1.Text = "夏季";
break;
case 9:
case 10:
case 11:
textBox1.Text = "秋季";
break;
case 12:
case 1:
case 2:
textBox1.Text = "冬季";
break;
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
switch(comboBox2.SelectedIndex)
{
case 0:
this.BackColor=Color.Red;
break;
case 1:
this.BackColor = Color.Yellow;
break;
case 2:
this.BackColor = Color.Blue;
break;
case 3:
this.BackColor = Color.Green;
break;
case 4:
this.BackColor = Color.Pink;
break;
}
}
结语:喜欢的请关注!
,