2015年11月5日 星期四

計算機(+-*/)

    public partial class Form1 : Form
    {
        int x, y,c=0;
        float a, b,d;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            x = Convert.ToInt32(textBox1.Text);
            x = int.Parse(textBox1.Text);
            y = Convert.ToInt32(textBox2.Text);
            y = int.Parse(textBox2.Text);
            c = x + y;
            label2 .Text=c.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            x = Convert.ToInt32(textBox1.Text);
            x = int.Parse(textBox1.Text);
            y = Convert.ToInt32(textBox2.Text);
            y = int.Parse(textBox2.Text);
            c = x - y;
            label2.Text = c.ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            x = Convert.ToInt32(textBox1.Text);
            x = int.Parse(textBox1.Text);
            y = Convert.ToInt32(textBox2.Text);
            y = int.Parse(textBox2.Text);
            c = x * y;
            label2.Text = c.ToString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            a = Convert.ToInt32(textBox1.Text);
            a = float.Parse(textBox1.Text);
            b = Convert.ToInt32(textBox2.Text);
            b = float.Parse(textBox2.Text);
            d = a / b;          
            label2.Text = d.ToString();
            if (b == 0) label2.Text = "除數不為零";
        }
    }
}

沒有留言:

張貼留言