计算器如何进行连续运算和混合运算?
这是我编的代码,只能运算一次就得按等号,求在此基础上实现连续运算和混合运算的方法如:5+6+7+8=?5+9*5=?private void button1_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
textBox1.Text = textBox1.Text + btn.Text; //以上两步能在Textbox中输入按钮的数字,用了老师教的方法
}
string a ;
string f;
double num1;
private void button14_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
a = textBox1.Text;
num1 = Convert.ToDouble(a);
textBox1.Text = "";
f = btn.Text; //以上获取第一个数并清空Textbox,f为运算符的类型(+、-、*、\)
}
private void button18_Click(object sender, EventArgs e)//以下为运算过程
{
if (f == "+")
{
double c = num1 + Convert.ToDouble(textBox1.Text);
textBox1.Text = Convert.ToString(c);
}
else if (f == "-")
{
double c = num1 - Convert.ToDouble(textBox1.Text);
textBox1.Text = Convert.ToString(c);
}
else if (f == "*")
{
double c = num1 * Convert.ToDouble(textBox1.Text);
textBox1.Text = Convert.ToString(c);
}
else if (f == "/")
{
double c = num1 / Convert.ToDouble(textBox1.Text);
textBox1.Text = Convert.ToString(c);
}
}
private void button17_Click(object sender, EventArgs e)//清空
{
textBox1.Text = "";
}
private void button11_Click(object sender, EventArgs e)
{
if (this.textBox1.Text != "" )
{
double d = double.Parse(this.textBox1.Text);
if (d != 0)
{
this.textBox1.Text = (-d).ToString();
}
}
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
string t;
private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
{
t = textBox1.Text;
}
private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.Text = t;
}
private void 文件ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void 版本信息ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 newform = new Form2();
newform.ShowDialog();
}
private void button19_Click(object sender, EventArgs e)
{
if (1 == textBox1.Text.Length)
{
textBox1.Text = "";
}
else
{
textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
ex4调试版.rar
(53.03 KB)
[ 本帖最后由 伍嚎 于 2011-5-7 23:17 编辑 ]