大家好,欢迎来到IT知识分享网。
基于《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;
}
}
IT知识分享网
窗体背景颜色变化:
IT知识分享网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;
}
}
结语:喜欢的请关注!
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/6786.html