菜鸟求指点
刚学习面向对象,写了个计算器的代码。求大虾们指点下有什么地方要改进。
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 (norepeat == false) { sign = "*"; first = textBox1.Text; textBox1.Text = ""; norepeat = true; } else { return; } } } private void weed_Click(object sender, EventArgs e) { if (sign2 == true) { if (norepeat == false) { sign = "/"; first = textBox1.Text; textBox1.Text = ""; norepeat = true; } else { return; } } } private void button20_Click(object sender, EventArgs e) { switch (sign) { case "+": final = double.Parse(first) + double.Parse(second); break; case "-": final = double.Parse(first) - double.Parse(second); break; case "*": final = double.Parse(first) * double.Parse(second); break; case "/": final = double.Parse(first) / double.Parse(second); break; } textBox1.Text = Convert.ToString(final); first = Convert.ToString(final); norepeat = false; } private void emptly_Click(object sender, EventArgs e) { first = ""; second = ""; textBox1.Text = ""; norepeat = false; sign2 = false; } private void Form1_Load(object sender, EventArgs e) { this.MaximizeBox = false; this.MinimizeBox = false; } }}