基于《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;
}
}
結語:喜歡的請關注!
,