2015年11月5日 星期四

簡易計算機


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

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

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

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

        private void button4_Click(object sender, EventArgs e)
        {
            x = Convert.ToInt32(textBox1.Text);
            x = float.Parse(textBox1.Text);
            y = Convert.ToInt32(textBox2.Text);
            y = float.Parse(textBox2.Text);
            z = x / y;
            label2.Text = z.ToString();
            if (b == 0)
            {
                label2.Text=("除術不可為0");
            }

        }
    }
}

沒有留言:

張貼留言