需要三個button和一個timer
public partial class Form1 : Form
{
int c = 2, d = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
c = c + 1;
button1.Text = c.ToString();
}
private void timer1_Tick(object sender, EventArgs e)
{
c = c + 1;
d = c % 3;
button1.Text = d.ToString();
button2.Text = d.ToString();
button3.Text = d.ToString();
if (d == 0)
{
button1.BackColor = System.Drawing.Color.FromName("RED");
}
else
{
button1.BackColor = System.Drawing.Color.FromName("White");
}
if (d == 1)
{
button2.BackColor = System.Drawing.Color.FromName("Yellow");
}
else
{
button2.BackColor = System.Drawing.Color.FromName("White");
}
if (d == 2)
{
button3.BackColor = System.Drawing.Color.FromName("Green");
}
else
{
button3.BackColor = System.Drawing.Color.FromName("White");
}
}
}
沒有留言:
張貼留言