2014年10月30日 星期四

C# 紅綠燈

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 WindowsFormsApplication7
{
    public partial class Form1 : Form
    {
        int a=0,b;
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            a = a + 1;
            b = a % 3;
            if (b == 1)
            {
                button1.BackColor = Color.Red;
                button2.BackColor = Color.Black;
                button3.BackColor = Color.Black;
            }
            else if (b == 2)
            {
                button1.BackColor = Color.Black;
                button2.BackColor = Color.Yellow;
                button3.BackColor = Color.Black;
            }
            else
            {
                button1.BackColor = Color.Black;
                button2.BackColor = Color.Black;
                button3.BackColor = Color.Green;
            }
        }
    }
}

沒有留言:

張貼留言