紅綠燈
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int c = 0, d = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
button1.BackColor = Color.WhiteSmoke;
button2.BackColor = Color.WhiteSmoke;
button3.BackColor = Color.WhiteSmoke;
c++;
d = c % 3;
if (d == 1)
{
button1.BackColor = Color.Red;
button2.BackColor = Color.WhiteSmoke;
button3.BackColor = Color.WhiteSmoke;
}
else if (d == 2)
{
button2.BackColor = Color.Yellow;
button1.BackColor = Color.WhiteSmoke;
button3.BackColor = Color.WhiteSmoke;
}
else if (d == 0)
{
button3.BackColor = Color.Green;
button2.BackColor = Color.WhiteSmoke;
button1.BackColor = Color.WhiteSmoke;
}
//button1.Text = c.ToString();
}
}
}
沒有留言:
張貼留言