using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Ex03_6
{
    public partial class Form1 : Form
    {
        public int intTime = 0;// 计时
        public int intFalg = 0;//标记

        public Form1()
        {
            InitializeComponent();
        }

        public void getFillColor()
        {
            Graphics g = this.CreateGraphics();//实例一个 Graphics对像
            switch (intFalg)
            {
                case 0:
                    g.FillEllipse(Brushes.DarkBlue, 20, 8, 60, 60);
                    g.FillEllipse(Brushes.DarkBlue, 110, 8, 60, 60);
                    g.FillEllipse(Brushes.DarkBlue, 200, 8, 60, 60);
                    break;
                case 1:              //红灯
                    g.FillEllipse(Brushes.Red, 20, 8, 60, 60);
                    g.FillEllipse(Brushes.DarkBlue, 110, 8, 60, 60);
                    g.FillEllipse(Brushes.DarkBlue, 200, 8, 60, 60);
                    break;
                case 2:           //绿灯
                    g.FillEllipse(Brushes.DarkBlue, 20, 8, 60, 60);
                    g.FillEllipse(Brushes.DarkBlue, 110, 8, 60, 60);
                    g.FillEllipse(Brushes.Green, 200, 8, 60, 60);
                    break;
                case 3:            //黄灯
                    g.FillEllipse(Brushes.DarkBlue, 20, 8, 60, 60);
                    g.FillEllipse(Brushes.Yellow, 110, 8, 60, 60);
                    g.FillEllipse(Brushes.DarkBlue, 200, 8, 60, 60);
                    break;            
            }
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            getFillColor();      //调用getFillColor方法     
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            intTime = 35;
            label1.Text = intTime.ToString();
            label1.ForeColor = Color.Red;
            timer1.Enabled = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            if (intTime != 0)
            {
                if (intTime < 10)
                {
                    label1.Text = "0" + intTime.ToString();
                    label1.ForeColor = Color.Red;
                }
                else
                {
                    label1.Text = intTime.ToString();
                    label1.ForeColor = Color.Red;
                }
                intTime--;
                intFalg = 1;                    //控制红绿黄灯刷新
                getFillColor();                //调用填充函数

            }
            else
            {

                label1.Text = "0" + intTime.ToString();
                timer1.Enabled = false;
                intFalg = 0;
                intTime = 5;//时间计时数
                timer1.Enabled = false;
                timer3.Enabled = true;
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            if (intTime != 0)
            {
                if (intTime < 10)
                {
                    label1.Text = "0" + intTime.ToString();
                    label1.ForeColor = Color.Green;
                }
                else
                {
                    label1.Text = intTime.ToString();
                    label1.ForeColor = Color.Green;
                }
                intFalg = 2;           //控制红绿黄灯刷新
                getFillColor();        //调用填充函数
                intTime--;
            }
            else
            {
                label1.Text = intTime.ToString();
                timer1.Enabled = false;
                intFalg = 0;
                intTime = 50;
                timer2.Enabled = false;
                timer1.Enabled = true;
            }
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            if (intTime != 0)
            {
                if (intTime < 10)
                {
                    label1.Text = "0" + intTime.ToString();
                    label1.ForeColor = Color.Yellow;
                }
                else
                {
                    label1.Text = "0" + intTime.ToString();
                    label1.ForeColor = Color.Yellow;
                }
                intTime--;
                intFalg = 3;            //控制红绿黄灯刷新
                getFillColor();         //调用填充函数
            }
            else
            {

                label1.Text = "0" + intTime.ToString();
                timer1.Enabled = false;
                intFalg = 0;
                intTime = 56;
                timer3.Enabled = false;
                timer2.Enabled = true;
            }
        }
    }
}
