1 向窗体拖入Timer组件
2 更改其Enable属性为true
3 其interval属性为300
4 在Tick事件中写入随机变色代码
1 private void timer1_Tick(object sender, EventArgs e) 2 { //随机变色代码 3 Random rand = new Random(); 4 int i = rand.Next(); 5 i = i % 6; 6 switch (i) { 7 case 0: 8 case 1: 9 BackColor=Color.Red; 10 break; 11 case 2: 12 case 3: 13 BackColor=Color.Yellow; 14 break; 15 case 4: 16 case 5: 17 BackColor = Color.Green; 18 break; 19 } 20 }
5 效果:
原文地址:https://www.cnblogs.com/feiyucha/p/9857766.html
时间: 2024-10-21 07:28:22