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

关于我编写的一个小型计算器。
我编了一个小型计算器,只会加减乘除,但是,我怎么越看越觉的别扭呢?希望大家帮我看看,特别是那些if,是不是用的太多了啊??第一次编写,希望大家别见怪哈。。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
  public partial class Form1 : Form
  {
  double z;
  double a;
  double save;
  public Form1()
  {
  InitializeComponent();
  }
  private void button1_Click(object sender, EventArgs e)
  {
  textBox1.Text += "1";
  }

  private void button2_Click(object sender, EventArgs e)
  {
  textBox1.Text += "2";
  }

  private void button3_Click(object sender, EventArgs e)
  {
  textBox1.Text += "3";
  }

  private void button4_Click(object sender, EventArgs e)
  {
  textBox1.Text += "4";
  }

  private void button5_Click(object sender, EventArgs e)
  {
  textBox1.Text += "5";
  }

  private void button6_Click(object sender, EventArgs e)
  {
  textBox1.Text += "6";
  }
  private void button7_Click(object sender, EventArgs e)
  {
  textBox1.Text += "7";
  }

  private void button8_Click(object sender, EventArgs e)
  {
  textBox1.Text += "8";
  }

  private void button9_Click(object sender, EventArgs e)
  {
  textBox1.Text += "9";
  }

  private void button0_Click(object sender, EventArgs e)
  {
  textBox1.Text += "0";
  }
  private void button_dot_Click(object sender, EventArgs e)
  {
  textBox1.Text += ".";
  }

  private void button_amount_Click(object sender, EventArgs e)
  {
  double equal = Convert.ToDouble(textBox1.Text);
   
  if (save == 1)
  {
  textBox1.Text = Convert.ToString(add(equal, a));
   
  }
  if (save == 2)
  {
  textBox1.Text = Convert.ToString(minus(a, equal));
   
  }
  if (save == 3)
  {
  textBox1.Text = Convert.ToString(multiply(equal, a));
   
  }
  if (save == 4)
  {
  textBox1.Text = Convert.ToString(divide(a, equal));
   
  }
   
   
  }

  private void button_add_Click(object sender, EventArgs e)
  {
  a = Convert.ToDouble(textBox1.Text);
  textBox1.Text = "";  
  sav