2014年12月7日 星期日

9/26 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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
int c = 0;
int r;
public Form1()
{
InitializeComponent();
}
private void button4_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
c++;
r = c % 3;
label1.Text = "r = " + r;
if (r == 1)
{
button1.BackColor = Color.Red;
button2.BackColor = Color.Black;
button3.BackColor = Color.Black;
}
else if (r == 2)
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Yellow;
button3.BackColor = Color.Black;
}
else if (r == 0)
{
button1.BackColor = Color.Black;
button2.BackColor = Color.Black;
button3.BackColor = Color.Green;
}
}
}
}

0 個意見:

張貼留言

訂閱 張貼留言 [Atom]

<< 首頁