怎样对下面计算器进行改进,使其可以进行连续的整数加减乘除运算
这是简易的计算器的winform程序代码
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication11
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
char flag;
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text += button1.Text.Trim();
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text += button2.Text.Trim();
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text += button3.Text.Trim();
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text += button4.Text.Trim();
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.Text += button5.Text.Trim();
}
private void button6_Click(object sender, EventArgs e)
{
textBox1.Text += button6.Text.Trim();
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text += button7.Text.Trim();
}
private void button8_Click(object sender, EventArgs e)
{
textBox1.Text += button8.Text.Trim();
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.Text += button9.Text.Trim();
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.Text += button10.Text.Trim();
}
private void button11_Click(object sender, EventArgs e)
{
textBox1.Text += button11.Text.Trim();
}
private void button12_Click(object sender, EventArgs e)
{
}
private void button13_Click(object sender, EventArgs e)
{
textBox1.Text += button13.Text.Trim();
flag = '+';
}
private void button14_Click(object sender, EventArgs e)
{
textBox1.Text += button14.Text.Trim();
flag = '-';
}
private void button15_Click(object sender, EventArgs e)
{
textBox1.Text += button15.Text.Trim();
flag = '*';
}
private void button16_Click(object sender, EventArgs e)
{
textBox1.Text += button16.Text.Trim();
flag = '/';
}
private void button17_Click(object sender, EventArgs e)
{
string s = textBox1.Text.Trim();
textBox1.Text = "";
char [] splitchar = {'+','-','*','/'};
string [] nums = s.Split(splitchar);
int [] numbers = new int [nums.Length];
int i = 0;
double result = 0;
foreach(string m in nums)
{
numbers[i] = Convert.ToInt32(nums[i]);
i++;
}
switch (flag)
{
case '+': result = numbers[0] + numbers[1]; break;
case '-': result = numbers[0] - numbers[1]; break;
case '*': result = numbers[0] * numbers[1]; break;
case '/':
try
{
result = numbers[0] / numbers[1];
}
catch(DivideByZeroException)
{
MessageBox.Show("除数不能为0");
}
break;
}
textBox1.Text = result.ToString();
}
}
}