2015年11月5日 星期四

計算機

string a,b;
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            label3.Text = "+";
            a = textBox1.Text;
            b = textBox2.Text;
            float c = float.Parse(a);
            float d = float.Parse(b);
            string e1 = (c+d).ToString();
            label2.Text = e1.ToString();

           
        }

        private void button2_Click(object sender, EventArgs e)
        {
        label3.Text = "-";
        a = textBox1.Text;
        b = textBox2.Text;
        float c = float.Parse(a);
        float d = float.Parse(b);
        string e1 = (c - d).ToString();
        label2.Text = e1.ToString();

        }

        private void button3_Click(object sender, EventArgs e)
        {
            label3.Text = "*";
            a = textBox1.Text;
            b = textBox2.Text;
            float c = float.Parse(a);
            float d = float.Parse(b);
            string e1 = (c * d).ToString();
            label2.Text = e1.ToString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            label3.Text = "/";
            a = textBox1.Text;
            b = textBox2.Text;
            float c = float.Parse(a);
            float d = float.Parse(b);
            if (d == 0)
                label2.Text = "Error";
            else
            {
                string e1 = (c / d).ToString();
                label2.Text = e1.ToString();
            }
        }
    }
}

2015年10月2日 星期五

程式設計工藝大師

紅綠燈

 public partial class Form1 : Form
    {
        int c = 0,d=0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            c = c + 1;
         
        }

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