日期:2014-05-18  浏览次数:21102 次

计算器1 ------C#窗体
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace计算器
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private float op1,op2;
        private string st, st1;
        private char opr;
        private double re;
        private void button1_Click(object sender, EventArgs e)
        {
            st = st + '0';
            this.textBox1.Text = st;
        }
 
        private void button4_Click(object sender, EventArgs e)
        {
            st = st + '1';
            this.textBox1.Text = st;
        }
 
        private void button5_Click(object sender, EventArgs e)
        {
            st = st + '2';
            this.textBox1.Text = st;
        }
 
        private void button6_Click(object sender, EventArgs e)
        {
            st = st + '3';
            this.textBox1.Text = st;
        }
 
        private void button7_Click(object sender, EventArgs e)
        {
            st = st + '4';
            this.textBox1.Text = st;
        }
 
        private void button8_Click(object sender, EventArgs e)
        {
            st = st + '5';
            this.textBox1.Text = st;
        }
 
        private void button9_Click(object sender, EventArgs e)
        {
            st = st + '6';
            this.textBox1.Text = st;
        }
 
        private void button10_Click(object sender, EventArgs e)
        {
           st = st + '7';
            this.textBox1.Text = st;
        }
 
        private void button11_Click(object sender, EventArgs e)
        {
            st = st + '8';
            this.textBox1.Text = st;
        }
 
        private void button12_Click(object sender, EventArgs e)
        {
            st = st + '9';
            this.textBox1.Text = st;
        }
 
        private void button17_Click(object sender, EventArgs e)
        {
            int count;
            count=st.Length-1;
            if(count>=0)
            {
                st = st.Substring(0,st.Length-1);
            }
            this.textBox1.Text = st;
        }
 
        private void button13_Click(object sender, EventArgs e)
        {
            opr = '+';
            st1 = st;
            st = "";
            this.textBox1.Text = st;
        }
 
        private void button14_Click(object sender, EventArgs e)
        {
            opr = '-';
            st1 = st;
            st = "";
            this.textBox1.Text = st;
        }
 
        private void button15_Click(object sender, EventArgs e)
        {
            opr = '*';
            st1 = st;
            st = "";
            this.textBox1.Text = st;
        }
 
        private void button16_Click(object sender, EventArgs e)
       {
            opr = '/';
            st1 = st;
            st = "";
            this.textBox1.Text = st;
        }
 
        private void button20_Click(object sender, EventArgs e)
        {
            op1 = float.Parse(st1);
            op2 = float.Parse(st);
            if (opr == '+')
                re = op1 + op2;
            if (opr == '-')
                re = op1 - op2;
            if (opr == '*')
                re = op1 * op2;
            if (opr == '/')
                re = op1 / op2;
            this.textBox1.Text = re.ToString();
        }
 
        private void button19_Click(object sender, EventArgs e)
        {
            st = "";
            st1 = "";
            this.textBox1.Text = "";
        }
 
        private void button18_Click(object sender, EventArgs e)
        {
            st = "";
            this.textBox1.Text = "";
        }
 
        private void button21_Click(object sender, EventArgs e)
        {
            op1 = float.Parse(st);
            re = Math.Sqrt(op1);
            this.textBox1.Text = re.ToString();
        }
 
        private void button3_Click(ob