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();
}
//public Single res;//存储结果
public string op;//存储操作符
public Single num1;//存储前数字
public Single num2;//存储操作符后数字
private Single res;
private void btn数字1_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
if (textBox1.Text != "0")
{
textBox1.Text += btn.Text;
}
else
{
textBox1.Text = "";
textBox1.Text += btn.Text;
}
}
。。。。。
数字0;数字2-数字9;
。。。。。
private void btn清零_Click(object sender, EventArgs e)
{
textBox1.Text = "";
res = 0;
num1 = 0;
}
public void btn加法_Click(object sender, EventArgs e)
{
num1=Convert.ToSingle(textBox1.Text);
Button btn = (Button)sender;
op = btn.Text;
res += num1;
num1 = 0;
textBox1.Text = Convert.ToString(num1);
}
private void btn等于_Click(object sender, EventArgs e)
{
// num1 = Convert.ToSingle(n);
num2 = Convert.ToSingle(textBox1.Text);
switch (op)
{
case"+":
{
res += num2;
break;
}
case "-":
{
this.res -= num2;
break;
}
case "*":
{
res *= num2;
break;
}
case "/":
{
res/= num2;
break;
}
}
textBox1.Text = Convert.ToString(res);
}
private void btn减法_Click(object sender, EventArgs e)
{
num1 = Convert.ToSingle(textBox1.Text);
Button btn = (Button)sender;
op = btn.Text;
res -= num1;
num1 = 0;
textBox1.Text = Convert.ToString(num1);
}
private void btn乘法_Click(object sender, EventArgs e)
{
num1 = Convert.ToSingle(textBox1.Text);
Button btn = (Button)sender;
op = btn.Text;
res *= num1;
num1 = 0;
textBox1.Text = Convert.ToString(num1);
}
private void btn除法_Click(object sender, EventArgs e)
{
num1 = Convert.ToSingle(textBox1.Text);
Button btn = (Button)sender;
op = btn.Text;
if (num1 != 0)
res /= num1;
else
return;
num1 = 0;
textBox1.Text = Convert.ToString(num1);
}
}
}
问题在于:不能进行混合运算(0-9);
请高手们帮小弟解决一下 啊,万分感激!