2014年9月26日 星期五

    public partial class Form1 : Form
    {
        int c;
        int r;
        public Form1()
        {

            InitializeComponent();
            c = 0;
        }

        private void button3_Click(object sender, EventArgs e)
        {

            c = c + 1;
            r = c % 2;
            label1.Text = "r=" + r;
            if (r == 0)
            {
                button1.Location = new Point(50, 50);
                button2.BackColor = Color.Black;
            }
            else
            {
                button1.Location = new Point(0, 0);
                button2.BackColor = Color.Yellow;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            c = c + 1;
            r = c % 3;
            label1.Text = "r=" + r;
            if (r == 0)
            {
                button1.BackColor = Color.Yellow;
                button2.BackColor = Color.Black;
                button3.BackColor = Color.Black;
            }
            else
                if (r == 1)
                {
                    button1.BackColor = Color.Black;
                    button2.BackColor = Color.Red;
                    button3.BackColor = Color.Black;
                }
                else
                {
                    button1.BackColor = Color.Black;
                    button2.BackColor = Color.Black;
                    button3.BackColor = Color.Green;
                }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            c = c + 1;
            r = c % 3;
            label1.Text = "r=" + r;
            if (r == 0)
            {
                button1.BackColor = Color.Yellow;
                button2.BackColor = Color.Black;
                button3.BackColor = Color.Black;
            }
            else
                if (r == 1)
                {
                    button1.BackColor = Color.Black;
                    button2.BackColor = Color.Red;
                    button3.BackColor = Color.Black;
                }
                else
                {
                    button1.BackColor = Color.Black;
                    button2.BackColor = Color.Black;
                    button3.BackColor = Color.Green;
                }




        }
    }
}