您好,欢迎访问三七文档
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespace双打闪动{publicpartialclassForm1:Form{intflag=1;intcount=10;publicForm1(){InitializeComponent();}voidpaint_LED(){Graphicsg=this.CreateGraphics();switch(flag){case1:{g.FillEllipse(Brushes.Red,60,60,50,50);g.FillEllipse(Brushes.Black,60,120,50,50);g.FillEllipse(Brushes.Black,60,180,50,50);break;}case2:{g.FillEllipse(Brushes.Black,60,60,50,50);g.FillEllipse(Brushes.Yellow,60,120,50,50);g.FillEllipse(Brushes.Black,60,180,50,50);break;}case3:{g.FillEllipse(Brushes.Black,60,60,50,50);g.FillEllipse(Brushes.Black,60,120,50,50);g.FillEllipse(Brushes.Green,60,180,50,50);break;}}}privatevoidForm1_Load(objectsender,EventArgse){timer1_red.Enabled=true;timer1_red.Interval=1000;timer1_yellow.Enabled=false;timer1_yellow.Interval=1000;timer1_green.Enabled=false;timer1_green.Interval=1000;}privatevoidtimer1_red_Tick(objectsender,EventArgse){if(count0){label1.Text=count.ToString();paint_LED();Graphicsg=this.CreateGraphics();count--;}else{timer1_red.Enabled=false;timer1_yellow.Enabled=true;timer1_green.Enabled=false;count=5;flag=2;}}privatevoidtimer1_yellow_Tick(objectsender,EventArgse){if(count0){label1.Text=count.ToString();paint_LED();Graphicsg=this.CreateGraphics();count--;}else{timer1_red.Enabled=false;timer1_yellow.Enabled=false;timer1_green.Enabled=true;count=10;flag=3;}}privatevoidtimer1_green_Tick(objectsender,EventArgse){if(count0){label1.Text=count.ToString();paint_LED();Graphicsg=this.CreateGraphics();count--;}else{timer1_red.Enabled=true;timer1_yellow.Enabled=false;timer1_green.Enabled=false;count=10;flag=1;}}}}
本文标题:C#实现红绿灯闪动
链接地址:https://www.777doc.com/doc-3239058 .html