2015年11月5日 星期四

C# 計算機加減乘除

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
     
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

     

        private void button1_Click(object sender, EventArgs e)
        {
            string b1;
            string b2;


            b1 = textBox1.Text;
            float a1 = float.Parse(b1);
            b2 = textBox2.Text;
            float a2 = float.Parse(b2);
            float c1 = a1 + a2;
            label2.Text = c1.ToString();
     
        }

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

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

            string b1;
            string b2;


            b1 = textBox1.Text;
            float a1 = float.Parse(b1);
            b2 = textBox2.Text;
            float a2 = float.Parse(b2);
            float c1 = a1 - a2;
            label2.Text = c1.ToString();
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            string b1;
            string b2;


            b1 = textBox1.Text;
            float a1 = float.Parse(b1);
            b2 = textBox2.Text;
            float a2 = float.Parse(b2);
            float c1 = a1 * a2;
            label2.Text = c1.ToString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string b1;
            string b2;


            b1 = textBox1.Text;
            float a1 = float.Parse(b1);
            b2 = textBox2.Text;
            float a2 = float.Parse(b2);
            float c1 = a1 / a2;
            label2.Text = c1.ToString();
            if(a2==0)
                label2.Text="分母不能為0";
        }
    }
}