当我调试代码时,第一个数字正在正确执行该功能,但是当我单击按钮“=”然后结果出现在文本框中,当我用来单击另一个按钮时,数字从结果继续而不是清除字段
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 CACalculator
{
public partial class Form1 : Form
{
double num1, num2, result;
string op;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btn9_Click(object sender, EventArgs e)
{
txtnum.Text = txtnum.Text + btn9.Text;
}
private void btn8_Click(object sender, EventArgs e)
{
txtnum.Text = txtnum.Text+ btn8.Text;
}
private void btn7_Click(object sender, EventArgs e)
{
txtnum.Text = txtnum.Text+ btn7.Text;
}
private void btn6_Click(object sender, EventArgs e)
{
txtnum.Text = txtnum.Text+ btn6.Text;
}
private void btn5_Click(object sender, EventArgs e)
{
txtnum.Text = txtnum.Text+ btn5.Text;
}
private void btn4_Click(object sender, EventArgs e)
{
txtnum.Text = txtnum.Text+ btn4.Text;
}
private void btn3_Click(object sender, EventArgs e)
{
txtnum.Text = txtnum.Text+ btn3.Text;
}
private void btn2_Click(object sender, EventArgs e)
{
txtnum.Text = txtnum.Text+ btn2.Text;
}
private void btn1_Click(object sender, EventArgs e)
{
txtnum.Text = txtnum.Text+ btn1.Text;
}
private void btn0_Click(object sender, EventArgs e)
{
txtnum.Text = txtnum.Text+ btn0.Text;
}
private void btnadd_Click(object sender, EventArgs e)
{
num1 = Convert.ToDouble(txtnum.Text);
txtnum.Clear();
op = btnadd.Text;
}
private void btnsub_Click(object sender, EventArgs e)
{
num1 = Convert.ToDouble(txtnum.Text);
txtnum.Clear();
op = btnsub.Text;
}
private void btnmul_Click(object sender, EventArgs e)
{
num1 = Convert.ToDouble(txtnum.Text);
txtnum.Clear();
op = btnmul.Text;
}
private void btndiv_Click(object sender, EventArgs e)
{
num1 = Convert.ToDouble(txtnum.Text);
txtnum.Clear();
op = btndiv.Text;
}
private void btnquo_Click(object sender, EventArgs e)
{
num1 = Convert.ToDouble(txtnum.Text);
txtnum.Clear();
op = btnquo.Text;
}
private void btneql_Click(object sender, EventArgs e)
{
num2 = Convert.ToDouble(txtnum.Text);
switch (op)
{
case "+":
result = num1 + num2;
break;
case "-":
result = num1 - num2;
break;
case "*":
result = num1 * num2;
break;
case "/":
result = num1 / num2;
break;
case "%":
result = num1 % num2;
break;
}
txtnum.Text = result.ToString();
}
private void btnC_Click(object sender, EventArgs e)
{
txtnum.Clear();
}
}
}