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

菜鸟求指点
刚学习面向对象,写了个计算器的代码。求大虾们指点下有什么地方要改进。
C# code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace jisuanqi2
{
    public partial class Form1 : Form
    {
        string first,second,sign;//first存放第一个数据,second存放第二个数据,sign判断哪个算数。
        bool norepeat=false,sign2=false;//sign解决重复按键。sign2解决用户先按下符号。
        double final;//存放最后结果。
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)//数字1-9  button1-9
        {
            textBox1.Text = textBox1.Text + button1.Text;
            second = textBox1.Text;
            sign2 = true;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button2.Text;
            second = textBox1.Text;
            sign2 = true;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button3.Text;
            second = textBox1.Text;
            sign2 =true;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button4.Text;
            second = textBox1.Text;
            sign2 = true;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button5.Text;
            second = textBox1.Text;
            sign2 = true;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button6.Text;
            second = textBox1.Text;
            sign2 = true;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button7.Text;
            second = textBox1.Text;
            sign2 = true;
        }

        private void button8_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button8.Text;
            second = textBox1.Text;
            sign2 = true;
        }

        private void button9_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button9.Text;
            second = textBox1.Text;
            sign2 = true;
        }

        private void button13_Click(object sender, EventArgs e)//小数点
        {
            textBox1.Text = textBox1.Text + button0.Text;
            second = textBox1.Text;
            sign2 = true;
        }

        private void button14_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button14.Text;
            second = textBox1.Text;
            sign2 = true;
        }

        private void plus_Click(object sender, EventArgs e)
        {   
            if(sign2==true)
            {
            if (norepeat == false)
            {
                sign = "+";
                first = textBox1.Text;
                textBox1.Text = "";
                norepeat = true;
            }
            else
            {
                return;
            }
            }
        }

        private void minus_Click(object sender, EventArgs e)
        {
            if (sign2 == true)
            {
                if (norepeat == false)
                {
                    sign = "-";
                    first = textBox1.Text;
                    textBox1.Text = "";
                    norepeat = true;
                }
                else
                {
                    return;
                }
            }
        }

        private void multiple_Click(object sender, EventArgs e)
        {
            if (sign2 == true)
            {
                if