tft每日頭條

 > 科技

 > c語言switch語句與if語句的轉換

c語言switch語句與if語句的轉換

科技 更新时间:2024-11-17 19:24:31

基于《C#中switch選擇語句配合下拉列表控件完成季節判斷與窗體顔色變化》視頻講解源代碼:

設計界面:

c語言switch語句與if語句的轉換(中switch選擇語句配合下拉列表完成季節判斷與窗體顔色變化代碼)1

季節判斷與窗體背景顔色變化

季節判斷:

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; } }

結語:喜歡的請關注!

,

更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!

查看全部

相关科技资讯推荐

热门科技资讯推荐

网友关注

Copyright 2023-2024 - www.tftnews.com All Rights Reserved